打字稿模块之间的区别是什么

Whet is the difference between typescript modules

我有一些关于 Typescript 模块的问题... 我正在用打字稿写一个 angular 1.5 应用程序,我这样写我的文件:

CarModel.ts

module app.models{
    export class Car{
        type:string;
        color: string;
    }
}

CarsController.ts

module app.controllers{

    import Car = app.Car;

    export class CarsController{
        private car:Car;
        ...
    }
}

但最近我在互联网上看到这种用法:

CarModel.ts

export class Car{
    type:string;
    color: string;
}

CarsController.ts

import {Car} from './models';
export class CarController{
    private car:Car;
    ....
} 

现在我想知道语法之间有什么区别? 还有什么区别:

module app.module1{}

declare module app.module1 {}

请注意,我使用的是 Visual Studio 2015,我的目标是 ES5。

您的第一个示例是一个内部模块。这将创建一个用于访问内容的全局变量。第二个是外部模块,它不创建全局变量。外部模块需要某种库,例如 systemjs 或 webpack 才能使它们在客户端工作。内部模块没有。

内部模块已重命名为名称空间,以防止这种确切类型的混淆。只需将关键字 module 替换为 namespace.