From 38e6d5bf153f49cde4b7a98bbaf4f2a7fee6f239 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Mon, 3 Feb 2020 23:16:53 +0300 Subject: [PATCH] feat(lib/es5): args rest type should always be array of any --- src/lib/es5.d.ts | 8 +++---- .../genericRestParameters1.errors.txt | 8 +++---- .../reference/inferTypes1.errors.txt | 24 +++++++++---------- .../parameterListAsTupleType.errors.txt | 8 +++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 24e2c489197c3..7d13dba63d4a6 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1473,22 +1473,22 @@ type NonNullable = T extends null | undefined ? never : T; /** * Obtain the parameters of a function type in a tuple */ -type Parameters any> = T extends (...args: infer P) => any ? P : never; +type Parameters any> = T extends (...args: infer P) => any ? P : never; /** * Obtain the parameters of a constructor function type in a tuple */ -type ConstructorParameters any> = T extends new (...args: infer P) => any ? P : never; +type ConstructorParameters any> = T extends new (...args: infer P) => any ? P : never; /** * Obtain the return type of a function type */ -type ReturnType any> = T extends (...args: any) => infer R ? R : any; +type ReturnType any> = T extends (...args: any) => infer R ? R : any; /** * Obtain the return type of a constructor function type */ -type InstanceType any> = T extends new (...args: any) => infer R ? R : any; +type InstanceType any> = T extends new (...args: any) => infer R ? R : any; /** * Marker for contextual 'this' type diff --git a/tests/baselines/reference/genericRestParameters1.errors.txt b/tests/baselines/reference/genericRestParameters1.errors.txt index cd9e799535bdb..24094a704ffc8 100644 --- a/tests/baselines/reference/genericRestParameters1.errors.txt +++ b/tests/baselines/reference/genericRestParameters1.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(22,11): error TS2556: Expected 3 arguments, but got 1 or more. tests/cases/conformance/types/rest/genericRestParameters1.ts(31,11): error TS2556: Expected 3 arguments, but got 1 or more. -tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'. - Type 'Function' provides no match for the signature '(...args: any): any'. +tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'. + Type 'Function' provides no match for the signature '(...args: any[]): any'. tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS2322: Type '(a: never) => void' is not assignable to type '(...args: any[]) => void'. Types of parameters 'a' and 'args' are incompatible. Type 'any' is not assignable to type 'never'. @@ -149,8 +149,8 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232 type T08 = ConstructorParameters void>; type T09 = Parameters; ~~~~~~~~ -!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'. -!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any): any'. +!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'. +!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any[]): any'. type Record1 = { move: [number, 'left' | 'right']; diff --git a/tests/baselines/reference/inferTypes1.errors.txt b/tests/baselines/reference/inferTypes1.errors.txt index 3779d91bf2b01..1d3d837999db2 100644 --- a/tests/baselines/reference/inferTypes1.errors.txt +++ b/tests/baselines/reference/inferTypes1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/types/conditional/inferTypes1.ts(31,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'. -tests/cases/conformance/types/conditional/inferTypes1.ts(32,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'. - Type 'Function' provides no match for the signature '(...args: any): any'. -tests/cases/conformance/types/conditional/inferTypes1.ts(38,25): error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'. -tests/cases/conformance/types/conditional/inferTypes1.ts(39,25): error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'. - Type 'Function' provides no match for the signature 'new (...args: any): any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(31,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any[]) => any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(32,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'. + Type 'Function' provides no match for the signature '(...args: any[]): any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(38,25): error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any[]) => any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(39,25): error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any[]) => any'. + Type 'Function' provides no match for the signature 'new (...args: any[]): any'. tests/cases/conformance/types/conditional/inferTypes1.ts(47,25): error TS2344: Type '(x: string, y: string) => number' does not satisfy the constraint '(x: any) => any'. tests/cases/conformance/types/conditional/inferTypes1.ts(48,25): error TS2344: Type 'Function' does not satisfy the constraint '(x: any) => any'. Type 'Function' provides no match for the signature '(x: any): any'. @@ -54,11 +54,11 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(145,40): error TS2322: type T16 = ReturnType; // never type T17 = ReturnType; // Error ~~~~~~ -!!! error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'. +!!! error TS2344: Type 'string' does not satisfy the constraint '(...args: any[]) => any'. type T18 = ReturnType; // Error ~~~~~~~~ -!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'. -!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any): any'. +!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'. +!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any[]): any'. type T19 = ReturnType<(x: string, ...args: T) => T[]>; // T[] type U10 = InstanceType; // C @@ -66,11 +66,11 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(145,40): error TS2322: type U12 = InstanceType; // never type U13 = InstanceType; // Error ~~~~~~ -!!! error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'. +!!! error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any[]) => any'. type U14 = InstanceType; // Error ~~~~~~~~ -!!! error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'. -!!! error TS2344: Type 'Function' provides no match for the signature 'new (...args: any): any'. +!!! error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any[]) => any'. +!!! error TS2344: Type 'Function' provides no match for the signature 'new (...args: any[]): any'. type ArgumentType any> = T extends (a: infer A) => any ? A : any; diff --git a/tests/baselines/reference/parameterListAsTupleType.errors.txt b/tests/baselines/reference/parameterListAsTupleType.errors.txt index 6bf3d74466e66..021138ec2babf 100644 --- a/tests/baselines/reference/parameterListAsTupleType.errors.txt +++ b/tests/baselines/reference/parameterListAsTupleType.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/parameterListAsTupleType.ts(8,17): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/parameterListAsTupleType.ts(16,23): error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any) => any'. - Type 'typeof C' provides no match for the signature '(...args: any): any'. +tests/cases/compiler/parameterListAsTupleType.ts(16,23): error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any[]) => any'. + Type 'typeof C' provides no match for the signature '(...args: any[]): any'. ==== tests/cases/compiler/parameterListAsTupleType.ts (2 errors) ==== @@ -23,8 +23,8 @@ tests/cases/compiler/parameterListAsTupleType.ts(16,23): error TS2344: Type 'typ type Cps = Parameters; // should not work ~~~~~~~~ -!!! error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any) => any'. -!!! error TS2344: Type 'typeof C' provides no match for the signature '(...args: any): any'. +!!! error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any[]) => any'. +!!! error TS2344: Type 'typeof C' provides no match for the signature '(...args: any[]): any'. type Ccps = ConstructorParameters; // should be [number, string] class D {