I'm trying to write the type for an array that contains objects, but with different types.
[
{
"id": "test",
"answer": "1"
},
{
"id": "test_multi",
"answers": [
{
"id": "skill_1"
},
{
"id": "skill_2"
}
]
},
]
My first approaches were:
prop: { id: string; answer: string | boolean | { id: string; answers: { id: string }[]} }[];
I guess in this case I'm assigning the different object to the answer prop.
Next approach
{ id: string; answer: string | boolean; } | { id: string; answers: { id: string }[] }[];
But in this case I guess I'm not allowing the array to be filled by the first type of object.
How can I write the type for "this array can contain this object AND/OR this object"?
( ... )from the beginning until the[]Array<Foo | Bar>