是否可以在打字稿中选择祖先命名空间

问题描述 投票:0回答:0

我生成的打字稿代码具有这样的嵌套命名空间:

namespace A {
        export type MyType = number
}

namespace B {
    const myValue: A.MyType = 6

    namespace A {
    }

}

该示例无法编译,因为命名空间“B”内的命名空间“A”隐藏了根级别的命名空间“A”。 有什么方法可以在不更改名称空间的任何名称的情况下访问根级名称空间“A”?

我试过了(没用):

namespace A {
        export type MyType = number
}

namespace A_root = A //<--not a valid syntax

namespace B {
    const myValue: A_root.MyType = 6

    namespace A {
    }

}

如果做不到,我将不得不为命名空间的名称(A_0、A_1 等)添加一个后缀,但这非常丑陋。

typescript nested namespaces
© www.soinside.com 2019 - 2024. All rights reserved.