有没有办法重用来自一个 .d.ts
的类型?另一个文件中的 .d.ts file
声明一个模块?
例如,假设我们有以下供应商文件:
node_modules/some-fancy-module/types.d.ts
export const valueA: number;
export const valueB: number;
现在在我的项目文件中,我想声明所有 *.special-file
进口将返回 valueA
和 valueB
如 https://www.typescriptlang.org/docs/handbook/modules.html 所示.打字.d.ts
declare module '*.special-file' {
export * from 'some-fancy-module/types.d.ts';
}
不幸的是,我无法使用这些类型:import {valueA} from './my.special-file';
错误:Module '"*.special-file"' has no exported member 'valueA'
截屏:CodeSandbox 如屏幕截图所示:
https://codesandbox.io/s/reexport-types-5h8hb?file=/src/index.ts
最佳答案
您可以在声明中导入然后导出。以下作品:
declare module '*.foo' {
import {valueA} from './third-party/types.d.ts';
export = valueA
}
关于typescript - 重新导出 typescript .d.ts 定义文件中的所有类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62553039/