// @target: es2015 // Repro from #2264 interface Y { 'i am a very certain type': Y } var y: Y = undefined; function destructure( something: a | Y, haveValue: (value: a) => r, haveY: (value: Y) => r ): r { return something === y ? haveY(y) : haveValue(something); } var value = Math.random() > 0.5 ? 'hey!' : undefined; var result = destructure(value, text => 'string', y => 'other one'); // text: string, y: Y // Repro from #4212 function isVoid(value: void | a): value is void { return undefined; } function isNonVoid(value: void | a) : value is a { return undefined; } function foo1(value: void|a): void { if (isVoid(value)) { value; // value is void } else { value; // value is a } } function baz1(value: void|a): void { if (isNonVoid(value)) { value; // value is a } else { value; // value is void } } // Repro from #5417 type Maybe = T | void; function get(x: U | void): U { return null; // just an example } let foo: Maybe; get(foo).toUpperCase(); // Ok // Repro from #5456 interface Man { walks: boolean; } interface Bear { roars: boolean; } interface Pig { oinks: boolean; } declare function pigify(y: T & Bear): T & Pig; declare var mbp: Man & Bear; pigify(mbp).oinks; // OK, mbp is treated as Pig pigify(mbp).walks; // Ok, mbp is treated as Man // Repros from #29815 interface ITest { name: 'test' } const createTestAsync = (): Promise => Promise.resolve().then(() => ({ name: 'test' })) const createTest = (): ITest => { return { name: 'test' } } declare function f1(x: T | U): T | U; declare function f2(x: T, y: U): T | U; let x1: string = f1('a'); let x2: string = f2('a', 'b'); // Repro from #30442 const func = () => {}; const assign = (a: T, b: U) => Object.assign(a, b); const res: (() => void) & { func: any } = assign(() => {}, { func });