1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
=== tests/cases/compiler/strictTypeofUnionNarrowing.ts ===
function stringify1(anything: { toString(): string } | undefined): string {
>stringify1 : Symbol(stringify1, Decl(strictTypeofUnionNarrowing.ts, 0, 0))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 0, 20))
>toString : Symbol(toString, Decl(strictTypeofUnionNarrowing.ts, 0, 31))
return typeof anything === "string" ? anything.toUpperCase() : "";
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 0, 20))
>anything.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 0, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
function stringify2(anything: {} | undefined): string {
>stringify2 : Symbol(stringify2, Decl(strictTypeofUnionNarrowing.ts, 2, 1))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 4, 20))
return typeof anything === "string" ? anything.toUpperCase() : "";
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 4, 20))
>anything.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 4, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
function stringify3(anything: unknown | undefined): string { // should simplify to just `unknown` which should narrow fine
>stringify3 : Symbol(stringify3, Decl(strictTypeofUnionNarrowing.ts, 6, 1))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 8, 20))
return typeof anything === "string" ? anything.toUpperCase() : "";
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 8, 20))
>anything.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 8, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
function stringify4(anything: { toString?(): string } | undefined): string {
>stringify4 : Symbol(stringify4, Decl(strictTypeofUnionNarrowing.ts, 10, 1))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 12, 20))
>toString : Symbol(toString, Decl(strictTypeofUnionNarrowing.ts, 12, 31))
return typeof anything === "string" ? anything.toUpperCase() : "";
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 12, 20))
>anything.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>anything : Symbol(anything, Decl(strictTypeofUnionNarrowing.ts, 12, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
|