diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8dd57a864e518..65c171c977c6f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19875,7 +19875,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const restIndex = sourceRestType || targetRestType ? paramCount - 1 : -1; for (let i = 0; i < paramCount; i++) { - const sourceType = i === restIndex ? getRestTypeAtPosition(source, i, /*readonly*/ true) : tryGetTypeAtPosition(source, i); + const sourceType = i === restIndex ? getRestTypeAtPosition(source, i) : tryGetTypeAtPosition(source, i); const targetType = i === restIndex ? getRestTypeAtPosition(target, i) : tryGetTypeAtPosition(target, i); if (sourceType && targetType) { // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter @@ -34691,12 +34691,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return undefined; } - function getRestTypeAtPosition(source: Signature, pos: number, readonly = false): Type { + function getRestTypeAtPosition(source: Signature, pos: number): Type { const parameterCount = getParameterCount(source); const minArgumentCount = getMinArgumentCount(source); const restType = getEffectiveRestType(source); if (restType && pos >= parameterCount - 1) { - return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType), readonly); + return pos === parameterCount - 1 ? restType : createArrayType(getIndexedAccessType(restType, numberType)); } const types = []; const flags = []; @@ -34715,7 +34715,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { names.push(name); } } - return createTupleType(types, flags, readonly, length(names) === length(types) ? names : undefined); + return createTupleType(types, flags, /*readonly*/ false, length(names) === length(types) ? names : undefined); } // Return the number of parameters in a signature. The rest parameter, if present, counts as one diff --git a/tests/baselines/reference/classImplementsMethodWIthTupleArgs.errors.txt b/tests/baselines/reference/classImplementsMethodWIthTupleArgs.errors.txt deleted file mode 100644 index 972b207db35ef..0000000000000 --- a/tests/baselines/reference/classImplementsMethodWIthTupleArgs.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/compiler/classImplementsMethodWIthTupleArgs.ts(2,5): error TS2416: Property 'set' in type 'MySettable' is not assignable to the same property in base type 'Settable'. - Type '{ (option: Record): void; (name: string, value: unknown): void; }' is not assignable to type '(...args: [option: Record] | [name: string, value: unknown] | [name: string]) => void'. - Types of parameters 'option' and 'args' are incompatible. - Type '[option: Record] | [name: string, value: unknown] | [name: string]' is not assignable to type 'readonly [option: Record]'. - Type '[name: string, value: unknown]' is not assignable to type 'readonly [option: Record]'. - Source has 2 element(s) but target allows only 1. -tests/cases/compiler/classImplementsMethodWIthTupleArgs.ts(3,5): error TS2416: Property 'set' in type 'MySettable' is not assignable to the same property in base type 'Settable'. - Type '{ (option: Record): void; (name: string, value: unknown): void; }' is not assignable to type '(...args: [option: Record] | [name: string, value: unknown] | [name: string]) => void'. - - -==== tests/cases/compiler/classImplementsMethodWIthTupleArgs.ts (2 errors) ==== - declare class MySettable implements Settable { - set(option: Record): void; - ~~~ -!!! error TS2416: Property 'set' in type 'MySettable' is not assignable to the same property in base type 'Settable'. -!!! error TS2416: Type '{ (option: Record): void; (name: string, value: unknown): void; }' is not assignable to type '(...args: [option: Record] | [name: string, value: unknown] | [name: string]) => void'. -!!! error TS2416: Types of parameters 'option' and 'args' are incompatible. -!!! error TS2416: Type '[option: Record] | [name: string, value: unknown] | [name: string]' is not assignable to type 'readonly [option: Record]'. -!!! error TS2416: Type '[name: string, value: unknown]' is not assignable to type 'readonly [option: Record]'. -!!! error TS2416: Source has 2 element(s) but target allows only 1. - set(name: string, value: unknown): void; - ~~~ -!!! error TS2416: Property 'set' in type 'MySettable' is not assignable to the same property in base type 'Settable'. -!!! error TS2416: Type '{ (option: Record): void; (name: string, value: unknown): void; }' is not assignable to type '(...args: [option: Record] | [name: string, value: unknown] | [name: string]) => void'. - } - - interface Settable { - set(...args: [option: Record] | [name: string, value: unknown] | [name: string]): void; - } - \ No newline at end of file diff --git a/tests/baselines/reference/contextualTupleTypeParameterReadonly.errors.txt b/tests/baselines/reference/contextualTupleTypeParameterReadonly.errors.txt new file mode 100644 index 0000000000000..bc6a4b1e38105 --- /dev/null +++ b/tests/baselines/reference/contextualTupleTypeParameterReadonly.errors.txt @@ -0,0 +1,33 @@ +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'. + Types of parameters 'a' and 'args' are incompatible. + Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'. + The type 'readonly [1, "1"]' is 'readonly' and cannot be assigned to the mutable type '[a: 1 | 2, b: "1" | "2"]'. + + +==== tests/cases/compiler/contextualTupleTypeParameterReadonly.ts (1 errors) ==== + declare function each>(cases: ReadonlyArray): (fn: (...args: T) => any) => void; + + const cases = [ + [1, '1'], + [2, '2'], + ] as const; + + const eacher = each(cases); + + eacher((a, b) => { + ~~~~~~~~~~~ +!!! 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'. +!!! error TS2345: Types of parameters 'a' and 'args' are incompatible. +!!! error TS2345: Type 'readonly [1, "1"] | readonly [2, "2"]' is not assignable to type '[a: 1 | 2, b: "1" | "2"]'. +!!! error TS2345: The type 'readonly [1, "1"]' is 'readonly' and cannot be assigned to the mutable type '[a: 1 | 2, b: "1" | "2"]'. + a; + b; + }); + + // TODO: https://github.com/microsoft/TypeScript/issues/53255 + eacher((...args) => { + const [a, b] = args; + a; + b; + }); + \ No newline at end of file diff --git a/tests/baselines/reference/contextualTupleTypeParameterReadonly.js b/tests/baselines/reference/contextualTupleTypeParameterReadonly.js index ce65ec919ea70..5899450df6899 100644 --- a/tests/baselines/reference/contextualTupleTypeParameterReadonly.js +++ b/tests/baselines/reference/contextualTupleTypeParameterReadonly.js @@ -13,6 +13,7 @@ eacher((a, b) => { b; }); +// TODO: https://github.com/microsoft/TypeScript/issues/53255 eacher((...args) => { const [a, b] = args; a; @@ -31,6 +32,7 @@ eacher(function (a, b) { a; b; }); +// TODO: https://github.com/microsoft/TypeScript/issues/53255 eacher(function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { diff --git a/tests/baselines/reference/contextualTupleTypeParameterReadonly.symbols b/tests/baselines/reference/contextualTupleTypeParameterReadonly.symbols index 25f165b697b81..a39644e374e98 100644 --- a/tests/baselines/reference/contextualTupleTypeParameterReadonly.symbols +++ b/tests/baselines/reference/contextualTupleTypeParameterReadonly.symbols @@ -36,20 +36,21 @@ eacher((a, b) => { }); +// TODO: https://github.com/microsoft/TypeScript/issues/53255 eacher((...args) => { >eacher : Symbol(eacher, Decl(contextualTupleTypeParameterReadonly.ts, 7, 5)) ->args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 14, 8)) +>args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 15, 8)) const [a, b] = args; ->a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 15, 11)) ->b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 15, 13)) ->args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 14, 8)) +>a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 16, 11)) +>b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 16, 13)) +>args : Symbol(args, Decl(contextualTupleTypeParameterReadonly.ts, 15, 8)) a; ->a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 15, 11)) +>a : Symbol(a, Decl(contextualTupleTypeParameterReadonly.ts, 16, 11)) b; ->b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 15, 13)) +>b : Symbol(b, Decl(contextualTupleTypeParameterReadonly.ts, 16, 13)) }); diff --git a/tests/baselines/reference/contextualTupleTypeParameterReadonly.types b/tests/baselines/reference/contextualTupleTypeParameterReadonly.types index 24b84ee2cc3a3..8809a21942d71 100644 --- a/tests/baselines/reference/contextualTupleTypeParameterReadonly.types +++ b/tests/baselines/reference/contextualTupleTypeParameterReadonly.types @@ -43,6 +43,7 @@ eacher((a, b) => { }); +// TODO: https://github.com/microsoft/TypeScript/issues/53255 eacher((...args) => { >eacher((...args) => { const [a, b] = args; a; b;}) : void >eacher : (fn: (...args: readonly [1, "1"] | readonly [2, "2"]) => any) => void diff --git a/tests/baselines/reference/genericRestParameters3.errors.txt b/tests/baselines/reference/genericRestParameters3.errors.txt index c2e350acf8115..d306bbf3a6748 100644 --- a/tests/baselines/reference/genericRestParameters3.errors.txt +++ b/tests/baselines/reference/genericRestParameters3.errors.txt @@ -6,19 +6,19 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(18,1): error TS2345 Source has 0 element(s) but target requires 2. 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'. Types of parameters 'y' and 'args' are incompatible. - Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: string]'. - Type '[number, boolean]' is not assignable to type 'readonly [y: string]'. + Type '[string] | [number, boolean]' is not assignable to type '[y: string]'. + Type '[number, boolean]' is not assignable to type '[y: string]'. Source has 2 element(s) but target allows only 1. 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'. Types of parameters 'y' and 'args' are incompatible. - Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: number, z: boolean]'. - Type '[string]' is not assignable to type 'readonly [y: number, z: boolean]'. + Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'. + Type '[string]' is not assignable to type '[y: number, z: boolean]'. Source has 1 element(s) but target requires 2. tests/cases/conformance/types/rest/genericRestParameters3.ts(35,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/rest/genericRestParameters3.ts(36,21): error TS2345: Argument of type 'number' is not assignable to parameter of type '(...args: CoolArray) => void'. tests/cases/conformance/types/rest/genericRestParameters3.ts(37,21): error TS2345: Argument of type '(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray) => void'. Types of parameters 'cb' and 'args' are incompatible. - Property '0' is missing in type 'CoolArray' but required in type 'readonly [cb: (...args: any[]) => void]'. + Property '0' is missing in type 'CoolArray' but required in type '[cb: (...args: any[]) => void]'. tests/cases/conformance/types/rest/genericRestParameters3.ts(44,32): error TS2345: Argument of type '[10, 20]' is not assignable to parameter of type 'CoolArray'. Property 'hello' is missing in type '[10, 20]' but required in type 'CoolArray'. tests/cases/conformance/types/rest/genericRestParameters3.ts(49,1): error TS2345: Argument of type '[]' is not assignable to parameter of type 'CoolArray'. @@ -69,15 +69,15 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345 ~~ !!! error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. !!! error TS2322: Types of parameters 'y' and 'args' are incompatible. -!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: string]'. -!!! error TS2322: Type '[number, boolean]' is not assignable to type 'readonly [y: string]'. +!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[y: string]'. +!!! error TS2322: Type '[number, boolean]' is not assignable to type '[y: string]'. !!! error TS2322: Source has 2 element(s) but target allows only 1. f1 = f3; // Error ~~ !!! error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. !!! error TS2322: Types of parameters 'y' and 'args' are incompatible. -!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type 'readonly [y: number, z: boolean]'. -!!! error TS2322: Type '[string]' is not assignable to type 'readonly [y: number, z: boolean]'. +!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[y: number, z: boolean]'. +!!! error TS2322: Type '[string]' is not assignable to type '[y: number, z: boolean]'. !!! error TS2322: Source has 1 element(s) but target requires 2. f1 = f4; @@ -100,7 +100,7 @@ tests/cases/conformance/types/rest/genericRestParameters3.ts(59,5): error TS2345 ~~~ !!! error TS2345: Argument of type '(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray) => void'. !!! error TS2345: Types of parameters 'cb' and 'args' are incompatible. -!!! error TS2345: Property '0' is missing in type 'CoolArray' but required in type 'readonly [cb: (...args: any[]) => void]'. +!!! error TS2345: Property '0' is missing in type 'CoolArray' but required in type '[cb: (...args: any[]) => void]'. function bar(...args: T): T { return args; diff --git a/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt b/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt index 31d69f7f07651..e182b72f57cdd 100644 --- a/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt +++ b/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt @@ -1,7 +1,7 @@ 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'. Types of parameters 'b' and 'args' are incompatible. - Type 'T' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'. - Type 'any[]' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'. + Type 'T' is not assignable to type '[b: T[0], ...x: T[number][]]'. + Type 'any[]' is not assignable to type '[b: T[0], ...x: T[number][]]'. Source provides no match for required element at position 0 in target. @@ -65,8 +65,8 @@ tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts(56,7): error ~~~~~~~~~~~~~~~~~~ !!! 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'. !!! error TS2345: Types of parameters 'b' and 'args' are incompatible. -!!! error TS2345: Type 'T' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'. -!!! error TS2345: Type 'any[]' is not assignable to type 'readonly [b: T[0], ...x: T[number][]]'. +!!! error TS2345: Type 'T' is not assignable to type '[b: T[0], ...x: T[number][]]'. +!!! error TS2345: Type 'any[]' is not assignable to type '[b: T[0], ...x: T[number][]]'. !!! error TS2345: Source provides no match for required element at position 0 in target. } diff --git a/tests/cases/compiler/contextualTupleTypeParameterReadonly.ts b/tests/cases/compiler/contextualTupleTypeParameterReadonly.ts index 1660832b37fd6..fd4383b1c2640 100644 --- a/tests/cases/compiler/contextualTupleTypeParameterReadonly.ts +++ b/tests/cases/compiler/contextualTupleTypeParameterReadonly.ts @@ -14,6 +14,7 @@ eacher((a, b) => { b; }); +// TODO: https://github.com/microsoft/TypeScript/issues/53255 eacher((...args) => { const [a, b] = args; a;