【问题标题】:Typescript - Import Namespace Into Another NamespaceTypescript - 将命名空间导入另一个命名空间
【发布时间】:2018-01-05 18:22:06
【问题描述】:

我想知道是否可以从一个打字稿 .d.ts 文件导出命名空间,然后将该命名空间导入另一个 .d.ts 文件,在该文件中在命名空间内使用它。

例子:

namespace_export.d.ts

export namespace Foo {
    interface foo {
        prop1: string;
    }
}

types.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
    }
}

testfile.ts

import { Types } from './types'

function testTypes(type: Types.Foo.foo) {
    console.log(type);
}

【问题讨论】:

    标签: javascript typescript namespaces


    【解决方案1】:

    我也想知道如何实现这一点。我找到了这个解决方案:

    import { Foo as fooAlias } from './namespace_export'
    export namespace Types {
      export import Foo = fooAlias;
      interface Bar {
        prop2: string
      }
    }
    

    希望这会有所帮助;)

    【讨论】:

    • 我不明白它是如何工作的),有人可以解释解释器如何理解“导出导入”吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多