|
| 1 | +=== tests/cases/compiler/voidUndefinedReduction.ts === |
| 2 | +// Repro from #42786 |
| 3 | + |
| 4 | +function isDefined<T>(value: T | undefined | null | void): value is T { |
| 5 | +>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0)) |
| 6 | +>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19)) |
| 7 | +>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) |
| 8 | +>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19)) |
| 9 | +>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) |
| 10 | +>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19)) |
| 11 | + |
| 12 | + return value !== undefined && value !== null; |
| 13 | +>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) |
| 14 | +>undefined : Symbol(undefined) |
| 15 | +>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22)) |
| 16 | +} |
| 17 | + |
| 18 | +declare const foo: string | undefined; |
| 19 | +>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13)) |
| 20 | + |
| 21 | +if (isDefined(foo)) { |
| 22 | +>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0)) |
| 23 | +>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13)) |
| 24 | + |
| 25 | + console.log(foo.toUpperCase()); |
| 26 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 27 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 28 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 29 | +>foo.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) |
| 30 | +>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13)) |
| 31 | +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) |
| 32 | +} |
| 33 | + |
0 commit comments