Typescript Clientside命名空间多个文件

时间:2016-07-28 12:16:14

标签: javascript typescript module namespaces

我正在编写一个从客户端浏览器访问的模块化API,为了组织起见,我希望将它们分成多个文件。我希望实现看起来像这样:

<script src="dist/Api.js"></script> <-- Do I have to include all scripts?

//Browser console
var n = new Api();
var m = new Api.NamespacedClass();
var o = Api.property;

根据我在文档中看到的内容,看起来最好的方法是通过namespaces modules,除非我&#39 ;我应该把两者结合起来让这个工作。

src/
├── models/
│   ├── Person.ts
│   ├── Thing.ts
│   Api.ts

Person.ts

namespace Api {
    export class Person {
        public create() {}
    }
}

Thing.ts

namespace Api {
    export class Thing {
        public create() {}
    }
}

Api.ts

//Insert references here
namespace Api {
    export class Api() { <--- I know this doesn't work.
        public property:string;
        constructor() {}
    }
}

我不知道如何设置正确的结构。有什么建议吗?

0 个答案:

没有答案