Giống như vậy:
interface GraphDatas {
firstTemperature: Period
internalTemperature: {
min: number;
max: number;
};
secondTemperature: Period;
thresholdAlerts: Threshold;
}
interface Period {
currentPeriod: number;
previousPeriod: any; // TO DO
}
interface Threshold extends Period {
hasBeenRead: number;
}
Bạn sẽ cần phải xuất khẩu giao diện bạn muốn sử dụng trong tập tin typescript của bạn sau đó:
export interface test{
listComputedDatas: GraphDatas;
}
Và trong mã của bạn:
import {test} from './pathToInterface';
...
randomProperty: test;
// Typescript should detect properties such as
// randomProperty.listComputedDatas.internalTemperature.min
EDIT: Bạn sẽ nhanh chóng tạo tệp của riêng mình theo cách thủ công hơn là thực hiện các dấu phẩy angular-cli
d ...
Nguồn
2017-04-25 14:52:03
Bạn có thể xem các tệp bản thiết kế: https://github.com/angular/angular-cli/tree/master/packages/%40angular/cli/blueprints/interface – jonrsharpe