0
У меня есть класс модели героя и адреса, одним из свойств Героя является его адрес, который состоит из: улицы, города .... Каков правильный путь указать это в конкретном классе исходного кода модели?Угловая 2: модель класса ts, состоящая из другой модели 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:
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")}
];
ОШИБКА при запуске "старт НПМ":
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'.