2016-04-14 88 views
12

我想知道什么是推荐的方法是在typescript中组织接口定义。在我的项目中,我有许多不同的类。每个类都可以有一个配置界面。目前,我已将所有这些接口定义收集到一个文件Interfaces.ts中,并从各个位置引用该文件。如何组织TypeScript接口

有没有更好的方法?

例子:https://github.com/blendsdk/blendjs/blob/devel/blend/src/common/Interfaces.ts

+3

直到像了StyleCop存在打字稿,对于“个人喜好”的说法很可能适用(只要你的代码编译)。我的个人偏好是将所有内容分解成它自己的文件,即接口IValidatable将存在于IValidatable.ts中 - 是的,最终本质上会有很多文件,但它应该有助于随时间的可维护性。 – series0ne

回答

2

我喜欢组织我的应用程序是这样的:

|-- app 
    |-- components 
    |-- directives 
    |-- services 
    |-- interfaces 
     |-- <feature/component name> 
      |-- <interface name>.interface.ts