I had the idea to use various types under a single 'dynamic' type, so I created:
export type ICandidate =
| ICandidatePlain
| ICandidateTalented
| ICandidateExperienced
The reason for this is because objects in the candidates array may have different properties from one another.
This ICandidate
type worked well as candidates were just a part of the object:
export interface Process {
id: string,
name: string,
candidates: ICandidate[]
}
The issue arose later when I needed to map all candidates to their specific component (which depends on type).
Here is a link to codesandbox, error on line #14
Is there a better way to make this work?
I suspect that the map function expects an array of objects with identical properties - or objects of type ICandidate
but not mixed types. How can I make it work with mixed types inside a single array?
My current workaround is using any
for the type like
data.map((candidate: any)=>{...}
, but I would prefer to find a solution with proper typing rather than just hacking around.