I have two types A
and B
. Both have k
as a common but with different types. But A got an additional field j
. When I union both and use them like this:
type A = {
k?: string;
j?: boolean
}
type B = {
k?: number;
}
type C = B | A;
function D({ k, j }: C) {
console.log(j)
}
I am getting the TypeScript error saying Property 'j' does not exist on type 'B'.
Can someone explain this behavior?