interface A {
type: 'a';
aProp: string;
}
interface B {
type: 'b';
bProp: number;
}
function printVal(x: A | B) {
if (x.type === 'a') {
console.log(x.aProp);
} else {
console.log(x.bProp);
}
}
printVal({ type: 'a', aProp: 'foo' });