I am trying to declare a list which can either be full of type 'a' data or type 'b' at a time. I understand why typescript is giving an error here, it doesn't know inside the loop whether the user data member inside temp variable inside the loop will be of type 'a' or 'b'. What I don't understand is how to fix it. I want an array that can be either full of one or the other type of data at a time.
error: Argument of type 'a | b' is not assignable to parameter of type 'b'. Property 'extra_porperty' is missing in type 'a' but required in type 'b'.
interface a {
id: number;
first_name: string;
last_name: string;
}
interface b extends a {
extra_porperty: string;
}
interface c {
user: a | b;
}
const newList: c[] = [];
const tempList: a[] | b[] = [];
newList.forEach((temp: c) => tempList.push(temp.user));
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)