
ALT type Alfa = { attributeA: string; }; type Bravo = { attributeB: string; }; function logProp(instance: Alfa | Bravo) { console.log(instance.attributeA ?? instance.attributeB); } const instanceA: Alfa = { attributeA: "aaa" }; const instanceB: Bravo = { attributeB: "bbb" }; logProp(instanceA); logProp(instanceB);

ALT type Alfa = { type: "alfa"; attributeA: string; }; type Bravo = { type: "bravo"; attributeB: string; }; function logProp(instance: Alfa | Bravo) { console.log(instance.type === 'alfa' ? instance.attributeA : instance.attributeB); } const instanceA: Alfa = { type: "alfa", attributeA: "aaa" }; const instanceB: Bravo = { type: "bravo", attributeB: "bbb" }; logProp(instanceA); logProp(instanceB);








