Closed
Description
interface A { isIt: true; text: string; }
interface B { isIt: false; value: number; }
type C = A | B;
const isIt = Math.random() > 0.5;
const c : C = isIt ? { isIt, text: 'hey' } : { isIt, value: 123 }; /* <-- expected to work, actual:
Type '{ isIt: boolean; text: string; } | { isIt: boolean; value: number; }' is not assignable to type 'C'.
Type '{ isIt: boolean; text: string; }' is not assignable to type 'C'.
Type '{ isIt: boolean; text: string; }' is not assignable to type 'B'.
Property 'value' is missing in type '{ isIt: boolean; text: string; }'.
*/
the following works tho:
const c : C = isIt ? { isIt: isIt, text: 'hey' } : { isIt: isIt, value: 123 };