Skip to content

Commit 604e355

Browse files
committed
Revert PR 53255
1 parent cbe9b3f commit 604e355

9 files changed

+62
-54
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19875,7 +19875,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1987519875
const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1;
1987619876

1987719877
for (let i = 0; i < paramCount; i++) {
19878-
const sourceType = i === restIndex ? getRestTypeAtPosition(source, i, /*readonly*/ true) : tryGetTypeAtPosition(source, i);
19878+
const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i);
1987919879
const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i);
1988019880
if (sourceType && targetType) {
1988119881
// In order to ensure that any generic type Foo<T> is at least co-variant with respect to T no matter
@@ -34691,12 +34691,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3469134691
return undefined;
3469234692
}
3469334693

34694-
function getRestTypeAtPosition(source: Signature, pos: number, readonly = false): Type {
34694+
function getRestTypeAtPosition(source: Signature, pos: number): Type {
3469534695
const parameterCount = getParameterCount(source);
3469634696
const minArgumentCount = getMinArgumentCount(source);
3469734697
const restType = getEffectiveRestType(source);
3469834698
if (restType && pos >= parameterCount - 1) {
34699-
return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType), readonly);
34699+
return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType));
3470034700
}
3470134701
const types = [];
3470234702
const flags = [];
@@ -34715,7 +34715,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3471534715
names.push(name);
3471634716
}
3471734717
}
34718-
return createTupleType(types, flags, readonly, length(names) === length(types) ? names : undefined);
34718+
return createTupleType(types, flags, /*readonly*/ false, length(names) === length(types) ? names : undefined);
3471934719
}
3472034720

3472134721
// Return the number of parameters in a signature. The rest parameter, if present, counts as one

tests/baselines/reference/classImplementsMethodWIthTupleArgs.errors.txt

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
tests/cases/compiler/contextualTupleTypeParameterReadonly.ts(10,8): error TS2345: Argument of type '(a: 1 | 2, b: "1" | "2") => void' is not assignable to parameter of type '(...args: readonly [1, "1"] | readonly [2, "2"]) => any'.
2+
Types of parameters 'a' and 'args' are incompatible.
3+
Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'.
4+
The type 'readonly [1, "1"]' is 'readonly' and cannot be assigned to the mutable type '[a: 1 | 2, b: "1" | "2"]'.
5+
6+
7+
==== tests/cases/compiler/contextualTupleTypeParameterReadonly.ts (1 errors) ====
8+
declare function each<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (fn: (...args: T) => any) => void;
9+
10+
const cases = [
11+
[1, '1'],
12+
[2, '2'],
13+
] as const;
14+
15+
const eacher = each(cases);
16+
17+
eacher((a, b) => {
18+
~~~~~~~~~~~
19+
!!! error TS2345: Argument of type '(a: 1 | 2, b: "1" | "2") => void' is not assignable to parameter of type '(...args: readonly [1, "1"] | readonly [2, "2"]) => any'.
20+
!!! error TS2345: Types of parameters 'a' and 'args' are incompatible.
21+
!!! error TS2345: Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'.
22+
!!! error TS2345: The type 'readonly [1, "1"]' is 'readonly' and cannot be assigned to the mutable type '[a: 1 | 2, b: "1" | "2"]'.
23+
a;
24+
b;
25+
});
26+
27+
// TODO: https://github.com/microsoft/TypeScript/issues/53255
28+
eacher((...args) => {
29+
const [a, b] = args;
30+
a;
31+
b;
32+
});
33+

tests/baselines/reference/contextualTupleTypeParameterReadonly.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ eacher((a, b) => {
1313
b;
1414
});
1515

16+
// TODO: https://github.com/microsoft/TypeScript/issues/53255
1617
eacher((...args) => {
1718
const [a, b] = args;
1819
a;
@@ -31,6 +32,7 @@ eacher(function (a, b) {
3132
a;
3233
b;
3334
});
35+
// TODO: https://github.com/microsoft/TypeScript/issues/53255
3436
eacher(function () {
3537
var args = [];
3638
for (var _i = 0; _i < arguments.length; _i++) {

tests/baselines/reference/contextualTupleTypeParameterReadonly.symbols

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,21 @@ eacher((a, b) => {
3636

3737
});
3838

39+
// TODO: https://github.com/microsoft/TypeScript/issues/53255
3940
eacher((...args) => {
4041
>eacher : Symbol(eacher, Decl(contextualTupleTypeParameterReadonly.ts, 7, 5))
41-
>args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 14, 8))
42+
>args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 15, 8))
4243

4344
const [a, b] = args;
44-
>a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 15, 11))
45-
>b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 15, 13))
46-
>args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 14, 8))
45+
>a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 16, 11))
46+
>b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 16, 13))
47+
>args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 15, 8))
4748

4849
a;
49-
>a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 15, 11))
50+
>a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 16, 11))
5051

5152
b;
52-
>b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 15, 13))
53+
>b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 16, 13))
5354

5455
});
5556

tests/baselines/reference/contextualTupleTypeParameterReadonly.types

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ eacher((a, b) => {
4343

4444
});
4545

46+
// TODO: https://github.com/microsoft/TypeScript/issues/53255
4647
eacher((...args) => {
4748
>eacher((...args) => { const [a, b] = args; a; b;}) : void
4849
>eacher : (fn: (...args: readonly [1, "1"] | readonly [2, "2"]) => any) => void

tests/baselines/reference/genericRestParameters3.errors.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(18,1): error TS2345
66
Source has 0 element(s) but target requires 2.
77
tests/cases/conformance/types/rest/genericRestParameters3.ts(23,1): error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
88
Types of parameters 'y' and 'args' are incompatible.
9-
Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: string]'.
10-
Type '[number, boolean]' is not assignable to type 'readonly [y: string]'.
9+
Type '[string] | [number, boolean]' is not assignable to type '[y: string]'.
10+
Type '[number, boolean]' is not assignable to type '[y: string]'.
1111
Source has 2 element(s) but target allows only 1.
1212
tests/cases/conformance/types/rest/genericRestParameters3.ts(24,1): error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
1313
Types of parameters 'y' and 'args' are incompatible.
14-
Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: number, z: boolean]'.
15-
Type '[string]' is not assignable to type 'readonly [y: number, z: boolean]'.
14+
Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'.
15+
Type '[string]' is not assignable to type '[y: number, z: boolean]'.
1616
Source has 1 element(s) but target requires 2.
1717
tests/cases/conformance/types/rest/genericRestParameters3.ts(35,1): error TS2554: Expected 1 arguments, but got 0.
1818
tests/cases/conformance/types/rest/genericRestParameters3.ts(36,21): error TS2345: Argument of type 'number' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
1919
tests/cases/conformance/types/rest/genericRestParameters3.ts(37,21): error TS2345: Argument of type '<T extends any[]>(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
2020
Types of parameters 'cb' and 'args' are incompatible.
21-
Property '0' is missing in type 'CoolArray<any>' but required in type 'readonly [cb: (...args: any[]) => void]'.
21+
Property '0' is missing in type 'CoolArray<any>' but required in type '[cb: (...args: any[]) => void]'.
2222
tests/cases/conformance/types/rest/genericRestParameters3.ts(44,32): error TS2345: Argument of type '[10, 20]' is not assignable to parameter of type 'CoolArray<number>'.
2323
Property 'hello' is missing in type '[10, 20]' but required in type 'CoolArray<number>'.
2424
tests/cases/conformance/types/rest/genericRestParameters3.ts(49,1): error TS2345: Argument of type '[]' is not assignable to parameter of type 'CoolArray<never>'.
@@ -69,15 +69,15 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345
6969
~~
7070
!!! error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
7171
!!! error TS2322: Types of parameters 'y' and 'args' are incompatible.
72-
!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: string]'.
73-
!!! error TS2322: Type '[number, boolean]' is not assignable to type 'readonly [y: string]'.
72+
!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[y: string]'.
73+
!!! error TS2322: Type '[number, boolean]' is not assignable to type '[y: string]'.
7474
!!! error TS2322: Source has 2 element(s) but target allows only 1.
7575
f1 = f3; // Error
7676
~~
7777
!!! error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'.
7878
!!! error TS2322: Types of parameters 'y' and 'args' are incompatible.
79-
!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: number, z: boolean]'.
80-
!!! error TS2322: Type '[string]' is not assignable to type 'readonly [y: number, z: boolean]'.
79+
!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'.
80+
!!! error TS2322: Type '[string]' is not assignable to type '[y: number, z: boolean]'.
8181
!!! error TS2322: Source has 1 element(s) but target requires 2.
8282
f1 = f4;
8383

@@ -100,7 +100,7 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345
100100
~~~
101101
!!! error TS2345: Argument of type '<T extends any[]>(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray<any>) => void'.
102102
!!! error TS2345: Types of parameters 'cb' and 'args' are incompatible.
103-
!!! error TS2345: Property '0' is missing in type 'CoolArray<any>' but required in type 'readonly [cb: (...args: any[]) => void]'.
103+
!!! error TS2345: Property '0' is missing in type 'CoolArray<any>' but required in type '[cb: (...args: any[]) => void]'.
104104

105105
function bar<T extends any[]>(...args: T): T {
106106
return args;

tests/baselines/reference/restTuplesFromContextualTypes.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts(56,7): error TS2345: Argument of type '(a: number, b: T[0], ...x: T[number][]) => void' is not assignable to parameter of type '(x: number, ...args: T) => void'.
22
Types of parameters 'b' and 'args' are incompatible.
3-
Type 'T' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'.
4-
Type 'any[]' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'.
3+
Type 'T' is not assignable to type '[b: T[0], ...x: T[number][]]'.
4+
Type 'any[]' is not assignable to type '[b: T[0], ...x: T[number][]]'.
55
Source provides no match for required element at position 0 in target.
66

77

@@ -65,8 +65,8 @@ tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts(56,7): error
6565
~~~~~~~~~~~~~~~~~~
6666
!!! error TS2345: Argument of type '(a: number, b: T[0], ...x: T[number][]) => void' is not assignable to parameter of type '(x: number, ...args: T) => void'.
6767
!!! error TS2345: Types of parameters 'b' and 'args' are incompatible.
68-
!!! error TS2345: Type 'T' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'.
69-
!!! error TS2345: Type 'any[]' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'.
68+
!!! error TS2345: Type 'T' is not assignable to type '[b: T[0], ...x: T[number][]]'.
69+
!!! error TS2345: Type 'any[]' is not assignable to type '[b: T[0], ...x: T[number][]]'.
7070
!!! error TS2345: Source provides no match for required element at position 0 in target.
7171
}
7272

tests/cases/compiler/contextualTupleTypeParameterReadonly.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ eacher((a, b) => {
1414
b;
1515
});
1616

17+
// TODO: https://github.com/microsoft/TypeScript/issues/53255
1718
eacher((...args) => {
1819
const [a, b] = args;
1920
a;

0 commit comments

Comments
 (0)