Skip to content

Commit 9bd1a32

Browse files
authored
Revert PR #53255 (#53464)
1 parent c66f8de commit 9bd1a32

12 files changed

+130
-24
lines changed

src/compiler/checker.ts

+4-4
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
@@ -34724,12 +34724,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3472434724
return undefined;
3472534725
}
3472634726

34727-
function getRestTypeAtPosition(source: Signature, pos: number, readonly = false): Type {
34727+
function getRestTypeAtPosition(source: Signature, pos: number): Type {
3472834728
const parameterCount = getParameterCount(source);
3472934729
const minArgumentCount = getMinArgumentCount(source);
3473034730
const restType = getEffectiveRestType(source);
3473134731
if (restType && pos >= parameterCount - 1) {
34732-
return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType), readonly);
34732+
return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType));
3473334733
}
3473434734
const types = [];
3473534735
const flags = [];
@@ -34748,7 +34748,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3474834748
names.push(name);
3474934749
}
3475034750
}
34751-
return createTupleType(types, flags, readonly, length(names) === length(types) ? names : undefined);
34751+
return createTupleType(types, flags, /*readonly*/ false, length(names) === length(types) ? names : undefined);
3475234752
}
3475334753

3475434754
// Return the number of parameters in a signature. The rest parameter, if present, counts as one
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [classImplementsMethodWIthTupleArgs.ts]
2+
declare class MySettable implements Settable {
3+
set(option: Record<string, unknown>): void;
4+
set(name: string, value: unknown): void;
5+
}
6+
7+
interface Settable {
8+
set(...args: [option: Record<string, unknown>] | [name: string, value: unknown] | [name: string]): void;
9+
}
10+
11+
12+
//// [classImplementsMethodWIthTupleArgs.js]
13+
"use strict";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/classImplementsMethodWIthTupleArgs.ts ===
2+
declare class MySettable implements Settable {
3+
>MySettable : Symbol(MySettable, Decl(classImplementsMethodWIthTupleArgs.ts, 0, 0))
4+
>Settable : Symbol(Settable, Decl(classImplementsMethodWIthTupleArgs.ts, 3, 1))
5+
6+
set(option: Record<string, unknown>): void;
7+
>set : Symbol(MySettable.set, Decl(classImplementsMethodWIthTupleArgs.ts, 0, 46), Decl(classImplementsMethodWIthTupleArgs.ts, 1, 47))
8+
>option : Symbol(option, Decl(classImplementsMethodWIthTupleArgs.ts, 1, 8))
9+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
10+
11+
set(name: string, value: unknown): void;
12+
>set : Symbol(MySettable.set, Decl(classImplementsMethodWIthTupleArgs.ts, 0, 46), Decl(classImplementsMethodWIthTupleArgs.ts, 1, 47))
13+
>name : Symbol(name, Decl(classImplementsMethodWIthTupleArgs.ts, 2, 8))
14+
>value : Symbol(value, Decl(classImplementsMethodWIthTupleArgs.ts, 2, 21))
15+
}
16+
17+
interface Settable {
18+
>Settable : Symbol(Settable, Decl(classImplementsMethodWIthTupleArgs.ts, 3, 1))
19+
20+
set(...args: [option: Record<string, unknown>] | [name: string, value: unknown] | [name: string]): void;
21+
>set : Symbol(Settable.set, Decl(classImplementsMethodWIthTupleArgs.ts, 5, 20))
22+
>args : Symbol(args, Decl(classImplementsMethodWIthTupleArgs.ts, 6, 8))
23+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
24+
}
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/compiler/classImplementsMethodWIthTupleArgs.ts ===
2+
declare class MySettable implements Settable {
3+
>MySettable : MySettable
4+
5+
set(option: Record<string, unknown>): void;
6+
>set : { (option: Record<string, unknown>): void; (name: string, value: unknown): void; }
7+
>option : Record<string, unknown>
8+
9+
set(name: string, value: unknown): void;
10+
>set : { (option: Record<string, unknown>): void; (name: string, value: unknown): void; }
11+
>name : string
12+
>value : unknown
13+
}
14+
15+
interface Settable {
16+
set(...args: [option: Record<string, unknown>] | [name: string, value: unknown] | [name: string]): void;
17+
>set : (...args: [option: Record<string, unknown>] | [name: string, value: unknown] | [name: string]) => void
18+
>args : [option: Record<string, unknown>] | [name: string, value: unknown] | [name: string]
19+
}
20+
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

+2
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

+7-6
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

+1
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

+10-10
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

+4-4
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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @strict: true
2+
3+
declare class MySettable implements Settable {
4+
set(option: Record<string, unknown>): void;
5+
set(name: string, value: unknown): void;
6+
}
7+
8+
interface Settable {
9+
set(...args: [option: Record<string, unknown>] | [name: string, value: unknown] | [name: string]): void;
10+
}

tests/cases/compiler/contextualTupleTypeParameterReadonly.ts

+1
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)