-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #35060 #35065
Fix #35060 #35065
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,30 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,12): erro | |
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,5): error TS2461: Type '{ 0: string; 1: number; length: 2; }' is not an array type. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2741: Property '2' is missing in type '[string, number]' but required in type '[number, number, number]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(19,5): error TS2741: Property '2' is missing in type 'StrNum' but required in type '[number, number, number]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[number, number, number]': 2, pop, push, concat, and 16 more. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, number, number]'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would be nice here to look for pairs of tuple-like things and elaborate if the lengths do not match? (Maybe not for this PR). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if there's a known |
||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2741: Property '2' is missing in type '[string, number]' but required in type '[string, number, number]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(22,5): error TS2741: Property '2' is missing in type 'StrNum' but required in type '[string, number, number]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[string, number, number]': 2, pop, push, concat, and 16 more. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string, number, number]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(24,5): error TS2322: Type '[string, number]' is not assignable to type '[number]'. | ||
Types of property '0' are incompatible. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error TS2322: Type 'StrNum' is not assignable to type '[number]'. | ||
Types of property '0' are incompatible. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[number]': pop, push, concat, join, and 15 more. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'. | ||
Types of property 'length' are incompatible. | ||
Type '2' is not assignable to type '1'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'. | ||
Types of property 'length' are incompatible. | ||
Type '2' is not assignable to type '1'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[string]': pop, push, concat, join, and 15 more. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(31,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'. | ||
Types of property '0' are incompatible. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[number, string]': pop, push, concat, join, and 15 more. | ||
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'. | ||
|
||
|
||
==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (17 errors) ==== | ||
|
@@ -58,7 +58,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error | |
!!! error TS2741: Property '2' is missing in type 'StrNum' but required in type '[number, number, number]'. | ||
var j3: [number, number, number] = z; | ||
~~ | ||
!!! error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[number, number, number]': 2, pop, push, concat, and 16 more. | ||
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, number, number]'. | ||
var k1: [string, number, number] = x; | ||
~~ | ||
!!! error TS2741: Property '2' is missing in type '[string, number]' but required in type '[string, number, number]'. | ||
|
@@ -67,7 +67,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error | |
!!! error TS2741: Property '2' is missing in type 'StrNum' but required in type '[string, number, number]'. | ||
var k3: [string, number, number] = z; | ||
~~ | ||
!!! error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[string, number, number]': 2, pop, push, concat, and 16 more. | ||
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string, number, number]'. | ||
var l1: [number] = x; | ||
~~ | ||
!!! error TS2322: Type '[string, number]' is not assignable to type '[number]'. | ||
|
@@ -80,7 +80,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error | |
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
var l3: [number] = z; | ||
~~ | ||
!!! error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[number]': pop, push, concat, join, and 15 more. | ||
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'. | ||
var m1: [string] = x; | ||
~~ | ||
!!! error TS2322: Type '[string, number]' is not assignable to type '[string]'. | ||
|
@@ -93,7 +93,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error | |
!!! error TS2322: Type '2' is not assignable to type '1'. | ||
var m3: [string] = z; | ||
~~ | ||
!!! error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[string]': pop, push, concat, join, and 15 more. | ||
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'. | ||
var n1: [number, string] = x; | ||
~~ | ||
!!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. | ||
|
@@ -105,7 +105,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error | |
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
var n3: [number, string] = z; | ||
~~ | ||
!!! error TS2740: Type '{ 0: string; 1: number; length: 2; }' is missing the following properties from type '[number, string]': pop, push, concat, join, and 15 more. | ||
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'. | ||
var o1: [string, number] = x; | ||
var o2: [string, number] = y; | ||
var o3: [string, number] = y; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,37 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(23,9): error TS2345: Ar | |
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(27,7): error TS2322: Type 'readonly [1]' is not assignable to type 'readonly []'. | ||
Types of property 'length' are incompatible. | ||
Type '1' is not assignable to type '0'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(30,7): error TS4104: The type 'readonly [1]' is 'readonly' and cannot be assigned to the mutable type '[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(33,7): error TS2322: Type '[1]' is not assignable to type 'readonly []'. | ||
Types of property 'length' are incompatible. | ||
Type '1' is not assignable to type '0'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(36,7): error TS2322: Type '[1]' is not assignable to type '[]'. | ||
Types of property 'length' are incompatible. | ||
Type '1' is not assignable to type '0'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(39,7): error TS2322: Type 'readonly number[]' is not assignable to type 'readonly boolean[]'. | ||
Type 'number' is not assignable to type 'boolean'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(42,7): error TS4104: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'boolean[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(45,7): error TS2322: Type 'number[]' is not assignable to type 'readonly boolean[]'. | ||
Type 'number' is not assignable to type 'boolean'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(48,7): error TS2322: Type 'number[]' is not assignable to type 'boolean[]'. | ||
Type 'number' is not assignable to type 'boolean'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(51,7): error TS2322: Type 'readonly [1]' is not assignable to type 'readonly boolean[]'. | ||
Type '1' is not assignable to type 'boolean'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(54,7): error TS4104: The type 'readonly [1]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(57,7): error TS2322: Type '[1]' is not assignable to type 'readonly boolean[]'. | ||
Type '1' is not assignable to type 'boolean'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(60,7): error TS2322: Type '[1]' is not assignable to type 'boolean[]'. | ||
Type '1' is not assignable to type 'boolean'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(63,7): error TS2741: Property '0' is missing in type 'readonly number[]' but required in type 'readonly [1]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(66,7): error TS2740: Type 'readonly number[]' is missing the following properties from type '[1]': 0, pop, push, reverse, and 4 more. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(69,7): error TS2741: Property '0' is missing in type 'number[]' but required in type 'readonly [1]'. | ||
tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(72,7): error TS2741: Property '0' is missing in type 'number[]' but required in type '[1]'. | ||
|
||
|
||
==== tests/cases/compiler/readonlyTupleAndArrayElaboration.ts (6 errors) ==== | ||
==== tests/cases/compiler/readonlyTupleAndArrayElaboration.ts (22 errors) ==== | ||
// @strict | ||
// #Repro from #30839 | ||
|
||
|
@@ -55,4 +83,96 @@ tests/cases/compiler/readonlyTupleAndArrayElaboration.ts(24,9): error TS2345: Ar | |
~ | ||
!!! 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[]'. | ||
|
||
const t1: readonly [1] = [1]; | ||
const t2: readonly [] = t1; | ||
~~ | ||
!!! error TS2322: Type 'readonly [1]' is not assignable to type 'readonly []'. | ||
!!! error TS2322: Types of property 'length' are incompatible. | ||
!!! error TS2322: Type '1' is not assignable to type '0'. | ||
|
||
const t3: readonly [1] = [1]; | ||
const t4: [] = t3; | ||
~~ | ||
!!! error TS4104: The type 'readonly [1]' is 'readonly' and cannot be assigned to the mutable type '[]'. | ||
|
||
const t5: [1] = [1]; | ||
const t6: readonly [] = t5; | ||
~~ | ||
!!! error TS2322: Type '[1]' is not assignable to type 'readonly []'. | ||
!!! error TS2322: Types of property 'length' are incompatible. | ||
!!! error TS2322: Type '1' is not assignable to type '0'. | ||
|
||
const t7: [1] = [1]; | ||
const t8: [] = t7; | ||
~~ | ||
!!! error TS2322: Type '[1]' is not assignable to type '[]'. | ||
!!! error TS2322: Types of property 'length' are incompatible. | ||
!!! error TS2322: Type '1' is not assignable to type '0'. | ||
|
||
const a1: readonly number[] = [1]; | ||
const a2: readonly boolean[] = a1; | ||
~~ | ||
!!! error TS2322: Type 'readonly number[]' is not assignable to type 'readonly boolean[]'. | ||
!!! error TS2322: Type 'number' is not assignable to type 'boolean'. | ||
|
||
const a3: readonly number[] = [1]; | ||
const a4: boolean[] = a3; | ||
~~ | ||
!!! error TS4104: The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'boolean[]'. | ||
|
||
const a5: number[] = [1]; | ||
const a6: readonly boolean [] = a5; | ||
~~ | ||
!!! error TS2322: Type 'number[]' is not assignable to type 'readonly boolean[]'. | ||
!!! error TS2322: Type 'number' is not assignable to type 'boolean'. | ||
|
||
const a7: number[] = [1]; | ||
const a8: boolean[] = a7; | ||
~~ | ||
!!! error TS2322: Type 'number[]' is not assignable to type 'boolean[]'. | ||
!!! error TS2322: Type 'number' is not assignable to type 'boolean'. | ||
|
||
const ta1: readonly [1] = [1]; | ||
const ta2: readonly boolean[] = ta1; | ||
~~~ | ||
!!! error TS2322: Type 'readonly [1]' is not assignable to type 'readonly boolean[]'. | ||
!!! error TS2322: Type '1' is not assignable to type 'boolean'. | ||
|
||
const ta3: readonly [1] = [1]; | ||
const ta4: number[] = ta3; | ||
~~~ | ||
!!! error TS4104: The type 'readonly [1]' is 'readonly' and cannot be assigned to the mutable type 'number[]'. | ||
|
||
const ta5: [1] = [1]; | ||
const ta6: readonly boolean[] = ta5; | ||
~~~ | ||
!!! error TS2322: Type '[1]' is not assignable to type 'readonly boolean[]'. | ||
!!! error TS2322: Type '1' is not assignable to type 'boolean'. | ||
|
||
const ta7: [1] = [1]; | ||
const ta8: boolean[] = ta7; | ||
~~~ | ||
!!! error TS2322: Type '[1]' is not assignable to type 'boolean[]'. | ||
!!! error TS2322: Type '1' is not assignable to type 'boolean'. | ||
|
||
const at1: readonly number[] = [1]; | ||
const at2: readonly [1] = at1; | ||
~~~ | ||
!!! error TS2741: Property '0' is missing in type 'readonly number[]' but required in type 'readonly [1]'. | ||
|
||
const at3: readonly number[] = [1]; | ||
const at4: [1] = at3; | ||
~~~ | ||
!!! error TS2740: Type 'readonly number[]' is missing the following properties from type '[1]': 0, pop, push, reverse, and 4 more. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come this one doesn't get the readonly error message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition for readonly arrays on the source only checked for arrays on the target - will change and look for tuples. |
||
|
||
const at5: number[] = [1]; | ||
const at6: readonly [1] = at5; | ||
~~~ | ||
!!! error TS2741: Property '0' is missing in type 'number[]' but required in type 'readonly [1]'. | ||
|
||
const at7: number[] = [1]; | ||
const at8: [1] = at7; | ||
~~~ | ||
!!! error TS2741: Property '0' is missing in type 'number[]' but required in type '[1]'. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tuple-like type just needs to have a
0
property, so this cast isn't safe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative is just to dumb down the error message and check if it's strictly a tuple type or array type that isn't readonly, only then giving the adjusted error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, was abit confused by the comment on
isTupleLikeType
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this check give the right error message for the following?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To elaborate, I think we're getting close, but
probably needs to be replaced with something like
so get rid of the
Like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is now:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some other baseline changes that remove:
... pop, push, concat, and 16 more.
. Is that reasonable?