interface A {
name: string;
}
interface B {
age: number;
}
function test(): A | B {
if (Math.random() > 0.5) {
return {
age: 28,
}
}
return {
name: 'zero'
}
};
const target1: A & B = test();
// Type 'A | B' is not assignable to type 'A & B'
const target2: A = test();
// Type 'A | B' is not assignable to type 'A'
const target3: B = test();
// Type 'A | B' is not assignable to type 'B'