我想要一个可以全局访问的接口(interface)(在单独的文件中定义),我该怎么做?
这是我的globals.d.ts
文件
import { Theme, Style } from './style/themes/theme.types'
declare global {
Theme
Style
}
这给了我一个错误
Statements are not allowed in ambient contexts.ts(1036)
'Theme' only refers to a type, but is being used as a value here.ts(2693)
最佳答案
这可能是一个 hack,因为如果放在 .ts
中会引发错误。文件,但放在 .d.ts
中时似乎可以工作文件。
这个想法是使用一个名称导入类型并使用另一个名称导出。src/globals.d.ts
:
import type { DeepPick as _DeepPick } from "ts-deep-pick";
declare global {
export { _DeepPick as DeepPick };
}
关于typescript - 如何在 TypeScript 中将类型重新导出为全局类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61973864/