0
私はHeroとAddressモデルクラスを持っています.Heroのプロパティの1つは、street、city ...で構成されている住所です。具体的なモデルのソースクラスでこれを指定するには?角2:別のモデルで構成されたモデルtsクラス
hero.ts:
import {Address} from './address';
export class Hero {
id: number;
name: string;
powers: string [];
address: Address;
}
address.ts:
export class Address {
street: string;
street2: string;
city: string;
state: string;
}
モックheroes.ts:私は "NPM開始" を実行し
import {Hero} from './hero';
export var HEROES: Hero[] = [
{"id": 11, "name": "Mr. Nice", "powers" : ['nice', 'helpful'], "address" : ("a", "b", "c", "d")},
{"id": 12, "name": "Narco", "powers" : ['nice', 'helpful'], "address" : ("a", "b", "c", "d")}
];
ERROR:
app/mock-heroes.ts(3,12): error TS2322: Type '{ "id": number; "name": string; "powers": string[]; "address": string; }[]' is not assignable to type 'Hero[]'.
Type '{ "id": number; "name": string; "powers": string[]; "address": string; }' is not assignable to type 'Hero'.
Types of property 'address' are incompatible.
Type 'string' is not assignable to type 'Address'.