typescript 如何使用覆盖重新导出?

qvsjd97n  于 2023-06-24  发布在  TypeScript
关注(0)|答案(3)|浏览(201)
export * form 'some-library'
export * from './myOverrides'
// error: [ts] Module 'some-module' has already
// exported a member named 'someFunc'.
// Consider explicitly re-exporting to resolve the ambiguity.

import * as SomeLib from 'some-library'
import * as MyOverrides from './myOverrides'

export { ...SomeLib, ...MyOverrides } // syntax error

const Overridden = { ...someLib, ...MyOverrides } // works
export { ...Overridden } // syntax error

我想避免挑选出所有命名的出口只是为了再出口他们;

import { a, b, c, d, e, ..... } from 'some-library'
export { a, b, c, d, e, .... }
export * from './myOverrides'
wmomyfyw

wmomyfyw1#

Guy Sensei:
https://github.com/systemjs/systemjs/issues/1031#issuecomment-171262430
我需要:

import { theFunction } from './myOverrides'

export * from 'some-library'
export { theFunction }

这是因为本地出口优先。

ozxc1zmp

ozxc1zmp2#

我发现这个工作得很好:

import * as packageA from "packageA";
import * as packageB from "packageB";

export default { ...packageA, ...packageB };
whlutmcx

whlutmcx3#

如果您想导出整个模块:

export * as MyOverrides from './myOverrides'

然后你可以在另一个文件中使用它:

import { MyOverrides } from './some-path'

MyOverrides.someFunc

相关问题