Handle inline polymorphism in typescript
Solution 1:
Here is how you can do it using Union Types. Read more here
type EmployeeItem = IEmployeeDeveloper | IEmployeeQa | IEmployeeManager;
let employees: Record<string, EmployeeItem> = {
'tom': {
type: empType.developer,
ID: '1',
name: 'tom',
projectId: '123',
featureID: 'xxx',
deadline: '01/01/2023'
},
'sham': {
type: empType.qa,
ID: '12',
name: 'sham',
projectId: '123',
bugCount: 10000
},
'harry': {
type: empType.manager,
ID: '3',
name: 'harry',
projectId: '123',
reporteeIDs: ['1', '2']
},
}