// @strict: true function f1(x: T, y: { a: T }, z: [T]): string { if (x) { x; x.length; return x; } if (y.a) { y.a.length; return y.a; } if (z[0]) { z[0].length; return z[0]; } return "hello"; } function f2(x: Extract | null): string { if (x) { x; x.length; return x; } return "hello"; } interface Box { item: T; } declare function isBox(x: any): x is Box; declare function isUndefined(x: unknown): x is undefined; declare function unbox(x: Box): T; function g1 | undefined>(x: T) { if (isBox(x)) { unbox(x); } } function g2 | undefined>(x: T) { if (!isUndefined(x)) { unbox(x); } } function g3 | undefined>(x: T) { if (!isBox(x)) { unbox(x); // Error } } function g4 | undefined>(x: T) { if (isUndefined(x)) { unbox(x); // Error } } // Repro from #13995 declare function takeA(val: 'A'): void; export function bounceAndTakeIfA(value: AB): AB { if (value === 'A') { takeA(value); return value; } else { return value; } } // Repro from #13995 type Common = { id: number }; type AA = { tag: 'A', id: number }; type BB = { tag: 'B', id: number, foo: number }; type MyUnion = AA | BB; const fn = (value: MyUnion) => { value.foo; // Error if ('foo' in value) { value.foo; } if (value.tag === 'B') { value.foo; } }; const fn2 = (value: T): MyUnion => { value.foo; // Error if ('foo' in value) { value.foo; } if (value.tag === 'B') { value.foo; } }; // Repro from #13995 type A1 = { testable: true doTest: () => void } type B1 = { testable: false }; type Union = A1 | B1 function notWorking(object: T) { if (!object.testable) return; object.doTest(); } // Repro from #42939 interface A { a: number | null; }; function get(key: K, obj: A): number { const value = obj[key]; if (value !== null) { return value; } return 0; }; // Repro from #44093 class EventEmitter { off(...args: [K, number] | [unknown, string]):void {} } function once>(emittingObject: T, eventName: keyof ET): void { emittingObject.off(eventName, 0); emittingObject.off(eventName as typeof eventName, 0); }