2
我有一个私人性质的一类,但是当我尝试创建这个元素,我得到以下错误的数组:手稿错误:私人财产丢失?
error TS2322: Type '{ "id": number; "totalTime": number; "team": { "id": number; "name": string; }; }[]' is not assignable to type 'Training[]'.
[0] Type '{ "id": number; "totalTime": number; "team": { "id": number; "name": string; }; }' is not assignable to type 'Training'.
[0] Property 'remainingTime' is missing in type '{ "id": number; "totalTime": number; "team": { "id": number; "name": string; }; }'
Array类:
import { TEAMS } from './mock-teams';
import { Training } from './training';
export var TRAININGS: Training[] = [
{"id": 0, "totalTime": 60, "team": {"id": TEAMS[0]['id'], "name": TEAMS[0]['name'] } },
{"id": 1, "totalTime": 60, "team": {"id": TEAMS[0]['id'], "name": TEAMS[0]['name'] } }
];
培训等级:
export class Training {
private remainingTime: number = 0;
constructor(
public id: number,
public totalTime: number,
public team?: Team) {
}
}
我不明白为什么打字稿抱怨私人财产,即使不在构造函数中。