I am trying to type the following
interface IStudentType {
[key: `${Students}`]: IStudent | IStudentMaths| IStudentPhysics
}
The issue I get is TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
Fair enough so I try
type StudentCategories = 'Mature' | 'Graduate' | 'Fresher' // these are the keys in the data
interface IStudentType {
[key: `${StudentCategories}`]: IStudent | IStudentMaths| IStudentPhysics
}
TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
Any ideas how to fix this?
${StudentCategories}in your key index type.Recordfor this. Example:type StudentType = Record<StudentCategories, IStudent | IStudentMaths | IStudentPhysics>