|
| 1 | +=== tests/cases/compiler/narrowingTypeofFunction.ts === |
| 2 | +type Meta = { foo: string } |
| 3 | +>Meta : Symbol(Meta, Decl(narrowingTypeofFunction.ts, 0, 0)) |
| 4 | +>foo : Symbol(foo, Decl(narrowingTypeofFunction.ts, 0, 13)) |
| 5 | + |
| 6 | +interface F { (): string } |
| 7 | +>F : Symbol(F, Decl(narrowingTypeofFunction.ts, 0, 27)) |
| 8 | + |
| 9 | +function f1(a: (F & Meta) | string) { |
| 10 | +>f1 : Symbol(f1, Decl(narrowingTypeofFunction.ts, 1, 26)) |
| 11 | +>a : Symbol(a, Decl(narrowingTypeofFunction.ts, 3, 12)) |
| 12 | +>F : Symbol(F, Decl(narrowingTypeofFunction.ts, 0, 27)) |
| 13 | +>Meta : Symbol(Meta, Decl(narrowingTypeofFunction.ts, 0, 0)) |
| 14 | + |
| 15 | + if (typeof a === "function") { |
| 16 | +>a : Symbol(a, Decl(narrowingTypeofFunction.ts, 3, 12)) |
| 17 | + |
| 18 | + a; |
| 19 | +>a : Symbol(a, Decl(narrowingTypeofFunction.ts, 3, 12)) |
| 20 | + } |
| 21 | + else { |
| 22 | + a; |
| 23 | +>a : Symbol(a, Decl(narrowingTypeofFunction.ts, 3, 12)) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +function f2<T>(x: (T & F) | T & string) { |
| 28 | +>f2 : Symbol(f2, Decl(narrowingTypeofFunction.ts, 10, 1)) |
| 29 | +>T : Symbol(T, Decl(narrowingTypeofFunction.ts, 12, 12)) |
| 30 | +>x : Symbol(x, Decl(narrowingTypeofFunction.ts, 12, 15)) |
| 31 | +>T : Symbol(T, Decl(narrowingTypeofFunction.ts, 12, 12)) |
| 32 | +>F : Symbol(F, Decl(narrowingTypeofFunction.ts, 0, 27)) |
| 33 | +>T : Symbol(T, Decl(narrowingTypeofFunction.ts, 12, 12)) |
| 34 | + |
| 35 | + if (typeof x === "function") { |
| 36 | +>x : Symbol(x, Decl(narrowingTypeofFunction.ts, 12, 15)) |
| 37 | + |
| 38 | + x; |
| 39 | +>x : Symbol(x, Decl(narrowingTypeofFunction.ts, 12, 15)) |
| 40 | + } |
| 41 | + else { |
| 42 | + x; |
| 43 | +>x : Symbol(x, Decl(narrowingTypeofFunction.ts, 12, 15)) |
| 44 | + } |
| 45 | +} |
0 commit comments