1// @target: es2015 2 3// Repro from #2264 4 5interface Y { 'i am a very certain type': Y } 6var y: Y = <Y>undefined; 7function destructure<a, r>( 8 something: a | Y, 9 haveValue: (value: a) => r, 10 haveY: (value: Y) => r 11): r { 12 return something === y ? haveY(y) : haveValue(<a>something); 13} 14 15var value = Math.random() > 0.5 ? 'hey!' : <Y>undefined; 16 17var result = destructure(value, text => 'string', y => 'other one'); // text: string, y: Y 18 19// Repro from #4212 20 21function isVoid<a>(value: void | a): value is void { 22 return undefined; 23} 24 25function isNonVoid<a>(value: void | a) : value is a { 26 return undefined; 27} 28 29function foo1<a>(value: void|a): void { 30 if (isVoid(value)) { 31 value; // value is void 32 } else { 33 value; // value is a 34 } 35} 36 37function baz1<a>(value: void|a): void { 38 if (isNonVoid(value)) { 39 value; // value is a 40 } else { 41 value; // value is void 42 } 43} 44 45// Repro from #5417 46 47type Maybe<T> = T | void; 48 49function get<U>(x: U | void): U { 50 return null; // just an example 51} 52 53let foo: Maybe<string>; 54get(foo).toUpperCase(); // Ok 55 56// Repro from #5456 57 58interface Man { 59 walks: boolean; 60} 61 62interface Bear { 63 roars: boolean; 64} 65 66interface Pig { 67 oinks: boolean; 68} 69 70declare function pigify<T>(y: T & Bear): T & Pig; 71declare var mbp: Man & Bear; 72 73pigify(mbp).oinks; // OK, mbp is treated as Pig 74pigify(mbp).walks; // Ok, mbp is treated as Man 75 76// Repros from #29815 77 78interface ITest { 79 name: 'test' 80} 81 82const createTestAsync = (): Promise<ITest> => Promise.resolve().then(() => ({ name: 'test' })) 83 84const createTest = (): ITest => { 85 return { name: 'test' } 86} 87 88declare function f1<T, U>(x: T | U): T | U; 89declare function f2<T, U>(x: T, y: U): T | U; 90 91let x1: string = f1('a'); 92let x2: string = f2('a', 'b'); 93 94// Repro from #30442 95 96const func = <T>() => {}; 97const assign = <T, U>(a: T, b: U) => Object.assign(a, b); 98const res: (() => void) & { func: any } = assign(() => {}, { func }); 99