|
| 1 | +//// [tests/cases/compiler/controlFlowForFunctionLike1.ts] //// |
| 2 | + |
| 3 | +=== controlFlowForFunctionLike1.ts === |
| 4 | +function test1(a: number | string) { |
| 5 | +>test1 : Symbol(test1, Decl(controlFlowForFunctionLike1.ts, 0, 0)) |
| 6 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 0, 15)) |
| 7 | + |
| 8 | + if (typeof a === "number") { |
| 9 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 0, 15)) |
| 10 | + |
| 11 | + const fn = (arg: typeof a) => true; |
| 12 | +>fn : Symbol(fn, Decl(controlFlowForFunctionLike1.ts, 2, 9)) |
| 13 | +>arg : Symbol(arg, Decl(controlFlowForFunctionLike1.ts, 2, 16)) |
| 14 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 0, 15)) |
| 15 | + |
| 16 | + return fn; |
| 17 | +>fn : Symbol(fn, Decl(controlFlowForFunctionLike1.ts, 2, 9)) |
| 18 | + } |
| 19 | + return; |
| 20 | +} |
| 21 | + |
| 22 | +test1(0)?.(100); |
| 23 | +>test1 : Symbol(test1, Decl(controlFlowForFunctionLike1.ts, 0, 0)) |
| 24 | + |
| 25 | +test1(0)?.(""); |
| 26 | +>test1 : Symbol(test1, Decl(controlFlowForFunctionLike1.ts, 0, 0)) |
| 27 | + |
| 28 | +function test2(a: number | string) { |
| 29 | +>test2 : Symbol(test2, Decl(controlFlowForFunctionLike1.ts, 9, 15)) |
| 30 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 11, 15)) |
| 31 | + |
| 32 | + if (typeof a === "number") { |
| 33 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 11, 15)) |
| 34 | + |
| 35 | + const fn: { (arg: typeof a): boolean; } = () => true; |
| 36 | +>fn : Symbol(fn, Decl(controlFlowForFunctionLike1.ts, 13, 9)) |
| 37 | +>arg : Symbol(arg, Decl(controlFlowForFunctionLike1.ts, 13, 17)) |
| 38 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 11, 15)) |
| 39 | + |
| 40 | + return fn; |
| 41 | +>fn : Symbol(fn, Decl(controlFlowForFunctionLike1.ts, 13, 9)) |
| 42 | + } |
| 43 | + return; |
| 44 | +} |
| 45 | + |
| 46 | +test2(0)?.(100); |
| 47 | +>test2 : Symbol(test2, Decl(controlFlowForFunctionLike1.ts, 9, 15)) |
| 48 | + |
| 49 | +test2(0)?.(""); |
| 50 | +>test2 : Symbol(test2, Decl(controlFlowForFunctionLike1.ts, 9, 15)) |
| 51 | + |
| 52 | +function test3(a: number | string) { |
| 53 | +>test3 : Symbol(test3, Decl(controlFlowForFunctionLike1.ts, 20, 15)) |
| 54 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 22, 15)) |
| 55 | + |
| 56 | + if (typeof a === "number") { |
| 57 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 22, 15)) |
| 58 | + |
| 59 | + return (arg: typeof a) => {}; |
| 60 | +>arg : Symbol(arg, Decl(controlFlowForFunctionLike1.ts, 24, 12)) |
| 61 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 22, 15)) |
| 62 | + } |
| 63 | + throw new Error(""); |
| 64 | +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2022.error.d.ts, --, --)) |
| 65 | +} |
| 66 | + |
| 67 | +test3(1)(100); |
| 68 | +>test3 : Symbol(test3, Decl(controlFlowForFunctionLike1.ts, 20, 15)) |
| 69 | + |
| 70 | +test3(1)(""); |
| 71 | +>test3 : Symbol(test3, Decl(controlFlowForFunctionLike1.ts, 20, 15)) |
| 72 | + |
| 73 | +function test4(a: number | string) { |
| 74 | +>test4 : Symbol(test4, Decl(controlFlowForFunctionLike1.ts, 30, 13)) |
| 75 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 32, 15)) |
| 76 | + |
| 77 | + let fn = (arg: typeof a) => {}; |
| 78 | +>fn : Symbol(fn, Decl(controlFlowForFunctionLike1.ts, 33, 5)) |
| 79 | +>arg : Symbol(arg, Decl(controlFlowForFunctionLike1.ts, 33, 12)) |
| 80 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 32, 15)) |
| 81 | + |
| 82 | + if (Math.random() && typeof a === "number") { |
| 83 | +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) |
| 84 | +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) |
| 85 | +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) |
| 86 | +>a : Symbol(a, Decl(controlFlowForFunctionLike1.ts, 32, 15)) |
| 87 | + |
| 88 | + return fn; |
| 89 | +>fn : Symbol(fn, Decl(controlFlowForFunctionLike1.ts, 33, 5)) |
| 90 | + } |
| 91 | + throw new Error(""); |
| 92 | +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2022.error.d.ts, --, --)) |
| 93 | +} |
| 94 | + |
| 95 | +test4(1)?.(100); |
| 96 | +>test4 : Symbol(test4, Decl(controlFlowForFunctionLike1.ts, 30, 13)) |
| 97 | + |
| 98 | +test4(1)?.(""); |
| 99 | +>test4 : Symbol(test4, Decl(controlFlowForFunctionLike1.ts, 30, 13)) |
| 100 | + |
0 commit comments