我想知道什么是推荐的方法是在typescript中组织接口定义。在我的项目中,我有许多不同的类。每个类都可以有一个配置界面。目前,我已将所有这些接口定义收集到一个文件Interfaces.ts
中,并从各个位置引用该文件。如何组织TypeScript接口
有没有更好的方法?
例子:https://github.com/blendsdk/blendjs/blob/devel/blend/src/common/Interfaces.ts
我想知道什么是推荐的方法是在typescript中组织接口定义。在我的项目中,我有许多不同的类。每个类都可以有一个配置界面。目前,我已将所有这些接口定义收集到一个文件Interfaces.ts
中,并从各个位置引用该文件。如何组织TypeScript接口
有没有更好的方法?
例子:https://github.com/blendsdk/blendjs/blob/devel/blend/src/common/Interfaces.ts
有
打字稿团队使用一种叫做types.ts
文件更好的方法:https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts
我做同样的在我的项目如http://alm.tools:https://github.com/alm-tools/alm/blob/master/src/common/types.ts
谢谢,这真的很有帮助!我想知道,是否将类型定义从'types.ts'放入全局名称空间,或者是否从每个使用其类型的文件引用'types.ts'? – Rotareti
我喜欢组织我的应用程序是这样的:
|-- app
|-- components
|-- directives
|-- services
|-- interfaces
|-- <feature/component name>
|-- <interface name>.interface.ts
直到像了StyleCop存在打字稿,对于“个人喜好”的说法很可能适用(只要你的代码编译)。我的个人偏好是将所有内容分解成它自己的文件,即接口IValidatable将存在于IValidatable.ts中 - 是的,最终本质上会有很多文件,但它应该有助于随时间的可维护性。 – series0ne