javascript - Typescript - 将命名空间导入另一个命名空间

标签 javascript typescript namespaces

我想知道是否可以从一个 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/

相关文章:

javascript - html/js : is there a "page loaded" event in single page applications?

javascript - React Native : . map() 函数在渲染中不显示任何内容

typescript - 减少 Typescript 中的 getter/setter 样板

c# - 不同程序集中系统命名空间类型和用户定义类型之间的命名冲突

变量中的 PHP 命名空间类

python-3.x - python 本地函数中未解析的引用

javascript - 谷歌地图溢出到外层

javascript - JSON 数据未返回 - JQuery AJAX

angular - Ionic 2 angular-moment-timezone - 无法重新声明 block 范围变量 'tz'

javascript - 如何期望并将枚举作为组件属性传递?