这是我的第一个问题,所以我希望我会正确地问它。所以,对于我的项目,我需要创建几个组,并在每个组中创建几个人。现在,我已经创建的组中的一个文件,谁是这样的人的一个文件:班级角2 2
import { Person} from '../person/person';
export class Group {
id: number;
name: string;
I: Person;
}
和:
export class Person {
name: string;
phone:number;
}
现在,当我想为我的小组一个模拟文件,我尝试这样做:
import { Group } from './group';
import { Person} from '../person/person';
I: Person= {
name:"test"
phone: 25
};
export const GROUPS: Group[] = [
{id: 1, name: "Chefs d'agence", I:Person},
]
(不注重这个名字,我是法国人),但它没有工作,所以我尝试这样的:
import { Group } from './group';
import { Person} from '../person/person';
export const GROUPS: Group[] = [
{id: 1, name: "Chefs d'agence", I:Person={name:"test",phone:25},
]
但最后,我用这种类型的错误完成对集团:
Type '{ id: number; name: string; I: typeof Individu; }[]' is not assignable to type 'Groupe[]'.
Type '{ id: number; name: string; I: typeof Individu; }' is not assignable to type 'Groupe'.
Types of property 'I' are incompatible.
Type 'typeof Individu' is not assignable to type 'Individu'.
Property 'nom' is missing in type 'typeof Individu'.
现在我不跟人的阵列,但只是一个人进行测试,但是我不知道如何做到这一点。
需要查看'Interface' – anshuVersatile
'I:Person = new Person(); I.name =“Something”.......' – anshuVersatile