【发布时间】:2020-10-14 14:15:07
【问题描述】:
有没有办法在另一个.d.ts file 中重用来自一个.d.ts 文件的类型来声明一个模块?
例如,假设我们有以下供应商文件:
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 所示。
typings.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
【问题讨论】:
-
其实你的代码运行的很好,能分享一下你的tsconfig吗?
-
我添加了一个带有 tsconfig 和问题的代码框
标签: typescript typescript-typings