【发布时间】:2019-07-29 07:48:43
【问题描述】:
我正在使用 Ionic / Angular 开发应用程序。为了处理 HTTP 响应,我创建了一个接口来管理 JSON 响应。我在文件底部添加了这个名为interface IOne 的接口。喜欢:
export Class Example {
private getExample() {
this.http.get(url, {}, {}).then((result) => { const data: IOne = result.data; });
return data;
}
}
export interface IOne {
name: string;
}
将来会创建多个接口,因为我将发出具有不同响应类型的多个 HTTP 请求。这样一来,我的Class Example 下会有一个很长的接口列表,这不整洁(我假设?)它看起来像这样:
export Class Example { }
export interface IOne {
name: string;
}
export interface ITwo {
age: number;
}
export interface IThree {
color: string;
}
我考虑过创建 1 个名为 interfaces.ts 的文件并将此文件导入 example.ts。这是一个好的解决方案吗?有更好的选择吗?具体来说:
管理和构建多个接口以保持良好的项目结构的最佳方法是什么?
【问题讨论】:
标签: angular typescript ionic-framework interface