typescript - 重新导出 typescript .d.ts 定义文件中的所有类型

标签 typescript typescript-typings

有没有办法重用来自一个 .d.ts 的类型?另一个文件中的 .d.ts file声明一个模块?
例如,假设我们有以下供应商文件:
node_modules/some-fancy-module/types.d.ts

  export const valueA: number;
  export const valueB: number;
现在在我的项目文件中,我想声明所有 *.special-file进口将返回 valueAvalueBhttps://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 screenshot of the issue
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/

相关文章:

typescript 默认导出未定义

typescript - 扩展库的类型

带有编号索引和可通过字符串键访问的自定义属性的 Typescript 数组接口(interface)

angular - ionic 2 : Modal doesn't close when clicking on backdrop

angular - 导入的服务在抽象类上未定义

javascript - 如何使用 react 在两列或多列中显示 map 的结果

typescript - tsconfig 中是否有一个选项可以将服务器和客户端编译到公共(public)和私有(private)文件夹?

TypeScript Compiler API 如何设置 Lib?

typescript - 如何在 Typescript 中创建嵌套枚举

typescript - 如何使用具有动态参数计数的方法输入动态对象