Issue
I need a way to declare array with a specific order of types to force setting the required properties of each type as
list: (Teacher , School , Student , Teacher)[] = [
{id:1,fName:'jo1',sName:'jo11',position:'first teacher'},
{id:1,name:'oxford',location'us'},
{id:1,name:'rob',level:'junior'},
{id:2,name:'gen',level:'Senior'},
{id:2,fName:'jo1',sName:'jo11',name:'jo222',position:'second teacher'}
]
interface Teacher{
id;
fName;
sName;
position;
}
interface School{
id;
name;
location;
}
interface Student {
id;
name;
level;
}
Solution
You need to define list
as a tuple
not an array type:
interface Teacher {
id: number;
fName: string;
sName: string;
position: string;
}
interface School {
id: number;
name: string;
location: string;
}
interface Student {
id: number;
name: string;
level: string;
}
let list: [Teacher, School, Student, Teacher] = [
{ id: 1, fName: 'jo1', sName: 'jo11', position: 'first teacher' },
{ id: 1, name: 'oxford', location'us'},
{ id: 1, name: 'rob', level: 'junior' },
{ id: 2, name: 'gen', level: 'Senior' },
{ id: 2, fName: 'jo1', sName: 'jo11', name: 'jo222', position: 'second teacher' }
]
Answered By - Abdellah Hariti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.