diff --git a/tests/baselines/reference/controlFlowIterationErrors.errors.txt b/tests/baselines/reference/controlFlowIterationErrors.errors.txt index 748bf05dfb7..737a9e9557b 100644 --- a/tests/baselines/reference/controlFlowIterationErrors.errors.txt +++ b/tests/baselines/reference/controlFlowIterationErrors.errors.txt @@ -1,14 +1,21 @@ -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(11,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(12,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(22,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(23,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(34,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(35,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. +tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(46,17): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'. Type 'string' is not assignable to type 'number'. +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. +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'. + Type 'boolean' is not assignable to type 'string | number'. +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. +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'. + Type 'boolean' is not assignable to type 'string | number'. -==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (4 errors) ==== +==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (8 errors) ==== + let cond: boolean; function len(s: string) { @@ -69,4 +76,57 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(45,17): error } x; } + + function asNumber(x: string | number): number { + return +x; + } + + function h1() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x = +x + 1; + x; + } + } + + function h2() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x = asNumber(x) + 1; + x; + } + } + + function h3() { + let x: string | number | boolean; + x = "0"; + while (cond) { + let y = asNumber(x); + ~ +!!! 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. + ~ +!!! error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. + x = y + 1; + x; + } + } + + function h4() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x; + let y = asNumber(x); + ~ +!!! 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. + ~ +!!! error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. + x = y + 1; + x; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowIterationErrors.js b/tests/baselines/reference/controlFlowIterationErrors.js index 6c4a9a0b7e0..eed54cc53a7 100644 --- a/tests/baselines/reference/controlFlowIterationErrors.js +++ b/tests/baselines/reference/controlFlowIterationErrors.js @@ -1,4 +1,5 @@ //// [controlFlowIterationErrors.ts] + let cond: boolean; function len(s: string) { @@ -47,6 +48,49 @@ function g2() { } x; } + +function asNumber(x: string | number): number { + return +x; +} + +function h1() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x = +x + 1; + x; + } +} + +function h2() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x = asNumber(x) + 1; + x; + } +} + +function h3() { + let x: string | number | boolean; + x = "0"; + while (cond) { + let y = asNumber(x); + x = y + 1; + x; + } +} + +function h4() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x; + let y = asNumber(x); + x = y + 1; + x; + } +} //// [controlFlowIterationErrors.js] @@ -90,3 +134,41 @@ function g2() { } x; } +function asNumber(x) { + return +x; +} +function h1() { + var x; + x = "0"; + while (cond) { + x = +x + 1; + x; + } +} +function h2() { + var x; + x = "0"; + while (cond) { + x = asNumber(x) + 1; + x; + } +} +function h3() { + var x; + x = "0"; + while (cond) { + var y = asNumber(x); + x = y + 1; + x; + } +} +function h4() { + var x; + x = "0"; + while (cond) { + x; + var y = asNumber(x); + x = y + 1; + x; + } +}