【问题标题】:Typescript, Atom plugin giving duplicate namespace definitions in typescript d.ts filesTypescript,Atom 插件在 typescript d.ts 文件中给出重复的命名空间定义
【发布时间】:2016-08-02 07:40:08
【问题描述】:

Typescript 支持 *.ts 文件的命名空间合并。以下示例在多个 *.d.ts 文件中使用重复命名空间来限制 d.ts 文件大小:

File: myRoot_common_utils.d.ts

  declare namespace myRoot {
    export namespace common {
      export namespace utils {
        export function fastTrim(foo: string);
      }
    }
}

File: myRoot_common_encoders.d.ts:

declare namespace myRoot {
   export namespace common {
      export namespace encoders {
          export function toBase64(foo: string);
      }
   }
}

使用 atom typescript 插件导致 Duplicate identifier 错误:

 myRoot_common_encoders.d.ts Duplicate identifier "common".

Typescript 命名空间合并是否仅限于 *.ts 文件?有什么建议的解决方法吗?

【问题讨论】:

    标签: typescript namespaces


    【解决方案1】:

    Typescript 命名空间合并是否仅限于 *.ts 文件

    没有。我无法重现。您很可能在编译上下文中有更多文件(有重复)或同一文件中的其他内容导致此问题。

    【讨论】:

    • 谢谢,你说得对。我发现了另一个声明“export var common: any;”在 MyRoot 命名空间的上下文中。删除后问题得到解决。尽管大多数 typescript 在线参考资料中没有明确说明,但除了 .ts 文件之外,d.ts 文件还支持命名空间合并。
    猜你喜欢
    • 2021-04-23
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    相关资源
    最近更新 更多