|
| 1 | +//// [implicitConstParameters.ts] |
| 2 | + |
| 3 | +function doSomething(cb: () => void) { |
| 4 | + cb(); |
| 5 | +} |
| 6 | + |
| 7 | +function fn(x: number | string) { |
| 8 | + if (typeof x === 'number') { |
| 9 | + doSomething(() => x.toFixed()); |
| 10 | + } |
| 11 | +} |
| 12 | + |
| 13 | +function f1(x: string | undefined) { |
| 14 | + if (!x) { |
| 15 | + return; |
| 16 | + } |
| 17 | + doSomething(() => x.length); |
| 18 | +} |
| 19 | + |
| 20 | +function f2(x: string | undefined) { |
| 21 | + if (x) { |
| 22 | + doSomething(() => { |
| 23 | + doSomething(() => x.length); |
| 24 | + }); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +function f3(x: string | undefined) { |
| 29 | + inner(); |
| 30 | + function inner() { |
| 31 | + if (x) { |
| 32 | + doSomething(() => x.length); |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +function f4(x: string | undefined) { |
| 38 | + x = "abc"; // causes x to be considered non-const |
| 39 | + if (x) { |
| 40 | + doSomething(() => x.length); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +function f5(x: string | undefined) { |
| 45 | + if (x) { |
| 46 | + doSomething(() => x.length); |
| 47 | + } |
| 48 | + x = "abc"; // causes x to be considered non-const |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +function f6(x: string | undefined) { |
| 53 | + const y = x || ""; |
| 54 | + if (x) { |
| 55 | + doSomething(() => y.length); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +//// [implicitConstParameters.js] |
| 60 | +function doSomething(cb) { |
| 61 | + cb(); |
| 62 | +} |
| 63 | +function fn(x) { |
| 64 | + if (typeof x === 'number') { |
| 65 | + doSomething(function () { return x.toFixed(); }); |
| 66 | + } |
| 67 | +} |
| 68 | +function f1(x) { |
| 69 | + if (!x) { |
| 70 | + return; |
| 71 | + } |
| 72 | + doSomething(function () { return x.length; }); |
| 73 | +} |
| 74 | +function f2(x) { |
| 75 | + if (x) { |
| 76 | + doSomething(function () { |
| 77 | + doSomething(function () { return x.length; }); |
| 78 | + }); |
| 79 | + } |
| 80 | +} |
| 81 | +function f3(x) { |
| 82 | + inner(); |
| 83 | + function inner() { |
| 84 | + if (x) { |
| 85 | + doSomething(function () { return x.length; }); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | +function f4(x) { |
| 90 | + x = "abc"; // causes x to be considered non-const |
| 91 | + if (x) { |
| 92 | + doSomething(function () { return x.length; }); |
| 93 | + } |
| 94 | +} |
| 95 | +function f5(x) { |
| 96 | + if (x) { |
| 97 | + doSomething(function () { return x.length; }); |
| 98 | + } |
| 99 | + x = "abc"; // causes x to be considered non-const |
| 100 | +} |
| 101 | +function f6(x) { |
| 102 | + var y = x || ""; |
| 103 | + if (x) { |
| 104 | + doSomething(function () { return y.length; }); |
| 105 | + } |
| 106 | +} |
0 commit comments