export interface Student {
name: string;
section: string;
phoneNumber: string;
}
export interface StudentDetails {
[key: number]: Student; //Or string instead of number
}
And use it like this:
//Valid
let studentDetails: StudentDetails = {
1: {
name: 'Test Person1',
section: 'Section 1',
phoneNumber: '12345678'
}
};
//Valid
studentDetails[2] = {
name: 'Test Person 2',
section: 'Section 2',
phoneNumber: '87654321'
};
//Invalid (properties in UpperCase)
studentDetails[3] = {
Name: 'Test Person 3',
Section: 'Section 3',
PhoneNumber: '52376724'
};
//Valid
let student: Student = studentDetails[2];