Code snippet to reproduce :
type Queries = Array<{
value: string | Queries;
}>;
function processQuery(query: Queries) {
console.log(query);
}
const temp: Queries = [{ value: [] }, { value: 'abc' }];
for (let i = 0; i < temp.length; i++)
if (Array.isArray(temp[i].value)) {
processQuery(temp[i].value);
}
Here in the line processQuery(temp[i].value) I am getting the error Argument of type 'string | Queries' is not assignable to parameter of type 'Queries'.
One thing I can do is to remove the error is to write processQuery(temp[i].value as Queries). This seems a bit hacky. Is there a better way to handle this?
Thanks.