我想知道是否可以从一个 typescript .d.ts 文件中导出一个命名空间,然后将该命名空间导入到另一个 .d.ts 文件中,并在其中使用它。
例子:
命名空间导出.d.ts
export namespace Foo {
interface foo {
prop1: string;
}
}
类型.d.ts
import { Foo } from './namespace_export'
export namespace Types {
Foo // <-- This doesn't work but is what I would like
interface Bar {
prop2: string
}
}
测试文件.ts
import { Types } from './types'
function testTypes(type: Types.Foo.foo) {
console.log(type);
}
最佳答案
我也想知道如何实现这一目标。我找到了这个解决方案:
import { Foo as fooAlias } from './namespace_export'
export namespace Types {
export import Foo = fooAlias;
interface Bar {
prop2: string
}
}
希望这有帮助;)
关于javascript - Typescript - 将命名空间导入另一个命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45394533/