|
1 |
| -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(11,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. |
| 1 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(12,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. |
2 | 2 | Type 'number' is not assignable to type 'string'.
|
3 |
| -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(22,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. |
| 3 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(23,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. |
4 | 4 | Type 'number' is not assignable to type 'string'.
|
5 |
| -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(34,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. |
| 5 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(35,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. |
6 | 6 | Type 'string' is not assignable to type 'number'.
|
7 |
| -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. |
| 7 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(46,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. |
8 | 8 | Type 'string' is not assignable to type 'number'.
|
| 9 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(77,13): error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. |
| 10 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(77,26): error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. |
| 11 | + Type 'boolean' is not assignable to type 'string | number'. |
| 12 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(88,13): error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. |
| 13 | +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(88,26): error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. |
| 14 | + Type 'boolean' is not assignable to type 'string | number'. |
9 | 15 |
|
10 | 16 |
|
11 |
| -==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (4 errors) ==== |
| 17 | +==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (8 errors) ==== |
| 18 | + |
12 | 19 | let cond: boolean;
|
13 | 20 |
|
14 | 21 | function len(s: string) {
|
@@ -69,4 +76,57 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error
|
69 | 76 | }
|
70 | 77 | x;
|
71 | 78 | }
|
| 79 | + |
| 80 | + function asNumber(x: string | number): number { |
| 81 | + return +x; |
| 82 | + } |
| 83 | + |
| 84 | + function h1() { |
| 85 | + let x: string | number | boolean; |
| 86 | + x = "0"; |
| 87 | + while (cond) { |
| 88 | + x = +x + 1; |
| 89 | + x; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + function h2() { |
| 94 | + let x: string | number | boolean; |
| 95 | + x = "0"; |
| 96 | + while (cond) { |
| 97 | + x = asNumber(x) + 1; |
| 98 | + x; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + function h3() { |
| 103 | + let x: string | number | boolean; |
| 104 | + x = "0"; |
| 105 | + while (cond) { |
| 106 | + let y = asNumber(x); |
| 107 | + ~ |
| 108 | +!!! error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. |
| 109 | + ~ |
| 110 | +!!! error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. |
| 111 | +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. |
| 112 | + x = y + 1; |
| 113 | + x; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + function h4() { |
| 118 | + let x: string | number | boolean; |
| 119 | + x = "0"; |
| 120 | + while (cond) { |
| 121 | + x; |
| 122 | + let y = asNumber(x); |
| 123 | + ~ |
| 124 | +!!! error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. |
| 125 | + ~ |
| 126 | +!!! error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. |
| 127 | +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. |
| 128 | + x = y + 1; |
| 129 | + x; |
| 130 | + } |
| 131 | + } |
72 | 132 |
|
0 commit comments