【发布时间】:2019-06-29 19:40:37
【问题描述】:
如何从 typescript 中的命名空间导出接口?这仅限于声明文件吗?这是我正在尝试做的一个示例:
namespace Foo {
export interface Bar {}
export class Baz {}
}
export const { Baz } = Foo; // Works just fine
export const { Bar } = Foo; // Type 'typeof Foo' has no property 'Bar' and no string index signature.
打字稿 3.3.1
值得注意的是,官方文档中有这个用例,所以当我看到它不起作用时我很困惑:https://www.typescriptlang.org/docs/handbook/namespaces.html
更新(感谢提香):
我的主要目标是导出这种类型,我使用 Titian 的建议解决了这个问题:
namespace Foo {
export interface Bar {}
export class Baz {}
}
export const type Bar = Foo.Bar // now exportable
【问题讨论】:
标签: typescript