Javascript 串联js文件中的Typescript命名空间和重复标识符

Javascript 串联js文件中的Typescript命名空间和重复标识符,javascript,angularjs,module,namespaces,typescript,Javascript,Angularjs,Module,Namespaces,Typescript,我是Typescript新手,正在尝试了解名称空间以及如何引用在单独文件中定义的接口。我来自.NETC#背景,所以我习惯于在自己的文件中创建每个类和接口 国际铁路服务: //// <reference path="../../../../typings/tsd.d.ts" /> /// <reference path="../../../../typings/app.d.ts" /> namespace Interfaces { export interface

我是Typescript新手,正在尝试了解名称空间以及如何引用在单独文件中定义的接口。我来自.NETC#背景,所以我习惯于在自己的文件中创建每个类和接口

国际铁路服务:

//// <reference path="../../../../typings/tsd.d.ts" />
/// <reference path="../../../../typings/app.d.ts" />

namespace Interfaces {
    export interface INationalRailService {
        getDepartures(city: String): ng.IPromise<IQueryResult>;
        getArrivals(city: String): ng.IPromise<IQueryResult>;
    }
}
在tsd.d.ts中,我引用了我正在使用的框架,即Angular、JQuery、Typescript、toastr和Angular route

在我的app.d.ts文件中,我引用了我创建的.ts文件

// Interfaces
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/ITrainServices.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/INationalRailService.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/IParameters.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/IJourney.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/IQueryResult.ts" />

// Implementations
/// <reference path="../src/app/NationalRailViewerApp/Implementations/QueryResult.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Implementations/Journey.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Implementations/NationalRailService.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Implementations/TrainServices.ts" />
//接口
/// 
/// 
/// 
/// 
/// 
//实现
/// 
/// 
/// 
/// 
通过在文件顶部添加引用路径标记,我可以让各种类、控制器和服务识别相关接口

当我试图将其转换为Javascript(ES5)时,我的问题就出现了。My gulp task runner使用{out:'output.js'}配置选项,使用gulp typescript将我的javascript输出到单个.js文件

然而,我收到了大量关于存在“重复标识符”接口的警告,随后,生成的角度模块将不会加载

如果我要通过一个公共名称空间使这些接口可用于我的其他文件,那么为什么这会在生成的Javascript中给我带来问题

我是否误用了namespace关键字或误解了它的工作原理?如果我打算将生成的javascript连接到单个文件中,是否可以不使用名称空间

我试图通过阅读下面的文章来解决这个问题


但我就是想不起在这个示例中应该使用哪些名称空间或模块。

结果是,问题出在我的编辑器(VS代码)上。当我关闭并重新打开编辑器后,我的项目被吞咽了一口,关于重复的错误消失了


感谢各位的回复。

这个示例对我来说很好,但是我没有使用reference标记来配置项目,而是使用tsc--init创建了一个tsconfig.json,因此看起来您所做的一切都是正确的,尽管我使用msbuild来传输我的TypeScript,这使得我不必使用标记(因为它会自动使用项目中的所有.ts文件)。您得到的阻止angular模块加载的实际运行时错误是什么?这只是一般的模块加载错误。不过,谢天谢地,现在包含了tsconfig.js文件(我想这就是修复它的原因)为了删除///引用并完全限定接口名称,我进行了一些修改,使其能够传输并成功运行。@如果您将关于使用tsconfig.json文件的评论作为答案,我将对其进行标记,因为这最终帮助了我的进步。@Garethotes谢谢,但看起来需要更多时间(为了更大的利益)如果你能给出解决问题所需的全部答案,那就更好了
// Interfaces
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/ITrainServices.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/INationalRailService.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/IParameters.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/IJourney.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Interfaces/IQueryResult.ts" />

// Implementations
/// <reference path="../src/app/NationalRailViewerApp/Implementations/QueryResult.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Implementations/Journey.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Implementations/NationalRailService.ts" />
/// <reference path="../src/app/NationalRailViewerApp/Implementations/TrainServices.ts" />