【问题标题】:Typescript: History and File are already defined打字稿:历史和文件已经定义
【发布时间】:2017-03-02 02:18:29
【问题描述】:

我使用 Typescript 编写了一个新应用程序,并编写了名为“File”和“History”的新类。但是,我发现这些名称与 Typescript 的内部名称相冲突。你知道如何避免这种碰撞吗?

我也看了这个链接,可惜链接失效了:typescript history js conflict

【问题讨论】:

    标签: typescript


    【解决方案1】:

    如果你导出你的类,那么你应该没有问题:

    file1.ts

    export class File { ... }
    
    export class History { ... }
    

    file2.ts

    import { File as MyFile, History as MyFistory } from "./file1";
    
    let file = new MyFile();
    

    import * as MyModule from "./file1";
    
    let file = new MyModule.File();
    

    如果您不使用模块,那么您需要重命名您的类以避免这种冲突。

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 2018-03-04
      • 2017-04-26
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      相关资源
      最近更新 更多