Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30916 from jack-williams/array-elaboration
Elaborate array and tuple relation errors
- Loading branch information
Showing
12 changed files
with
322 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(2,21): error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'. | ||
Type 'Map<string, number>' is missing the following properties from type '[string, number]': 0, 1, length, pop, and 22 more. | ||
|
||
|
||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (1 errors) ==== | ||
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } | ||
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'. | ||
!!! error TS2345: Type 'Map<string, number>' is missing the following properties from type '[string, number]': 0, 1, length, pop, and 22 more. | ||
!!! error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/baselines/reference/readonlyTupleAndArrayElaboration.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(10,20): error TS2345: Argument of type 'readonly [3, 4]' is not assignable to parameter of type '[number, number]'. | ||
The type 'readonly [3, 4]' is 'readonly' and cannot be assigned to the mutable type '[number, number]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(13,8): error TS2345: Argument of type 'readonly [3, 4]' is not assignable to parameter of type 'number[]'. | ||
The type 'readonly [3, 4]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(16,9): error TS2345: Argument of type 'readonly [3, 4]' is not assignable to parameter of type 'number[]'. | ||
The type 'readonly [3, 4]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(22,9): error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'. | ||
The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(23,9): error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'. | ||
The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(24,9): error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'. | ||
The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
|
||
|
||
==== tests/cases/compiler/readonlyTupleAndArrayElaboration.ts (6 errors) ==== | ||
// @strict | ||
// #Repro from #30839 | ||
|
||
let point = [3, 4] as const; | ||
|
||
function distanceFromOrigin([x, y]: [number, number]) { | ||
return Math.sqrt(x ** 2 + y ** 2); | ||
} | ||
|
||
distanceFromOrigin(point); | ||
~~~~~ | ||
!!! error TS2345: Argument of type 'readonly [3, 4]' is not assignable to parameter of type '[number, number]'. | ||
!!! error TS2345: The type 'readonly [3, 4]' is 'readonly' and cannot be assigned to the mutable type '[number, number]'. | ||
|
||
declare function arryFn(x: number[]): void; | ||
arryFn(point); | ||
~~~~~ | ||
!!! error TS2345: Argument of type 'readonly [3, 4]' is not assignable to parameter of type 'number[]'. | ||
!!! error TS2345: The type 'readonly [3, 4]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
|
||
declare function arryFn2(x: Array<number>): void; | ||
arryFn2(point); | ||
~~~~~ | ||
!!! error TS2345: Argument of type 'readonly [3, 4]' is not assignable to parameter of type 'number[]'. | ||
!!! error TS2345: The type 'readonly [3, 4]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
|
||
declare const a: readonly number[]; | ||
declare const b: Readonly<number[]>; | ||
declare const c: ReadonlyArray<number>; | ||
|
||
arryFn2(a); | ||
~ | ||
!!! error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'. | ||
!!! error TS2345: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
arryFn2(b); | ||
~ | ||
!!! error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'. | ||
!!! error TS2345: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
arryFn2(c); | ||
~ | ||
!!! error TS2345: Argument of type 'readonly number[]' is not assignable to parameter of type 'number[]'. | ||
!!! error TS2345: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
|
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/readonlyTupleAndArrayElaboration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//// [readonlyTupleAndArrayElaboration.ts] | ||
// @strict | ||
// #Repro from #30839 | ||
|
||
let point = [3, 4] as const; | ||
|
||
function distanceFromOrigin([x, y]: [number, number]) { | ||
return Math.sqrt(x ** 2 + y ** 2); | ||
} | ||
|
||
distanceFromOrigin(point); | ||
|
||
declare function arryFn(x: number[]): void; | ||
arryFn(point); | ||
|
||
declare function arryFn2(x: Array<number>): void; | ||
arryFn2(point); | ||
|
||
declare const a: readonly number[]; | ||
declare const b: Readonly<number[]>; | ||
declare const c: ReadonlyArray<number>; | ||
|
||
arryFn2(a); | ||
arryFn2(b); | ||
arryFn2(c); | ||
|
||
|
||
//// [readonlyTupleAndArrayElaboration.js] | ||
// @strict | ||
// #Repro from #30839 | ||
var point = [3, 4]; | ||
function distanceFromOrigin(_a) { | ||
var x = _a[0], y = _a[1]; | ||
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); | ||
} | ||
distanceFromOrigin(point); | ||
arryFn(point); | ||
arryFn2(point); | ||
arryFn2(a); | ||
arryFn2(b); | ||
arryFn2(c); |
Oops, something went wrong.