Skip to content

Commit 38e6d5b

Browse files
committed
feat(lib/es5): args rest type should always be array of any
1 parent ef8eb0c commit 38e6d5b

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/lib/es5.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,22 +1473,22 @@ type NonNullable<T> = T extends null | undefined ? never : T;
14731473
/**
14741474
* Obtain the parameters of a function type in a tuple
14751475
*/
1476-
type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
1476+
type Parameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
14771477

14781478
/**
14791479
* Obtain the parameters of a constructor function type in a tuple
14801480
*/
1481-
type ConstructorParameters<T extends new (...args: any) => any> = T extends new (...args: infer P) => any ? P : never;
1481+
type ConstructorParameters<T extends new (...args: any[]) => any> = T extends new (...args: infer P) => any ? P : never;
14821482

14831483
/**
14841484
* Obtain the return type of a function type
14851485
*/
1486-
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
1486+
type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any) => infer R ? R : any;
14871487

14881488
/**
14891489
* Obtain the return type of a constructor function type
14901490
*/
1491-
type InstanceType<T extends new (...args: any) => any> = T extends new (...args: any) => infer R ? R : any;
1491+
type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any) => infer R ? R : any;
14921492

14931493
/**
14941494
* Marker for contextual 'this' type

tests/baselines/reference/genericRestParameters1.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/genericRestParameters1.ts(22,11): error TS2556: Expected 3 arguments, but got 1 or more.
22
tests/cases/conformance/types/rest/genericRestParameters1.ts(31,11): error TS2556: Expected 3 arguments, but got 1 or more.
3-
tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'.
4-
Type 'Function' provides no match for the signature '(...args: any): any'.
3+
tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'.
4+
Type 'Function' provides no match for the signature '(...args: any[]): any'.
55
tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS2322: Type '(a: never) => void' is not assignable to type '(...args: any[]) => void'.
66
Types of parameters 'a' and 'args' are incompatible.
77
Type 'any' is not assignable to type 'never'.
@@ -149,8 +149,8 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232
149149
type T08<T extends any[]> = ConstructorParameters<new (...args: T) => void>;
150150
type T09 = Parameters<Function>;
151151
~~~~~~~~
152-
!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'.
153-
!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any): any'.
152+
!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'.
153+
!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any[]): any'.
154154

155155
type Record1 = {
156156
move: [number, 'left' | 'right'];

tests/baselines/reference/inferTypes1.errors.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/types/conditional/inferTypes1.ts(31,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'.
2-
tests/cases/conformance/types/conditional/inferTypes1.ts(32,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'.
3-
Type 'Function' provides no match for the signature '(...args: any): any'.
4-
tests/cases/conformance/types/conditional/inferTypes1.ts(38,25): error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'.
5-
tests/cases/conformance/types/conditional/inferTypes1.ts(39,25): error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'.
6-
Type 'Function' provides no match for the signature 'new (...args: any): any'.
1+
tests/cases/conformance/types/conditional/inferTypes1.ts(31,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any[]) => any'.
2+
tests/cases/conformance/types/conditional/inferTypes1.ts(32,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'.
3+
Type 'Function' provides no match for the signature '(...args: any[]): any'.
4+
tests/cases/conformance/types/conditional/inferTypes1.ts(38,25): error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any[]) => any'.
5+
tests/cases/conformance/types/conditional/inferTypes1.ts(39,25): error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any[]) => any'.
6+
Type 'Function' provides no match for the signature 'new (...args: any[]): any'.
77
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'.
88
tests/cases/conformance/types/conditional/inferTypes1.ts(48,25): error TS2344: Type 'Function' does not satisfy the constraint '(x: any) => any'.
99
Type 'Function' provides no match for the signature '(x: any): any'.
@@ -54,23 +54,23 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(145,40): error TS2322:
5454
type T16 = ReturnType<never>; // never
5555
type T17 = ReturnType<string>; // Error
5656
~~~~~~
57-
!!! error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'.
57+
!!! error TS2344: Type 'string' does not satisfy the constraint '(...args: any[]) => any'.
5858
type T18 = ReturnType<Function>; // Error
5959
~~~~~~~~
60-
!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'.
61-
!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any): any'.
60+
!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'.
61+
!!! error TS2344: Type 'Function' provides no match for the signature '(...args: any[]): any'.
6262
type T19<T extends any[]> = ReturnType<(x: string, ...args: T) => T[]>; // T[]
6363

6464
type U10 = InstanceType<typeof C>; // C
6565
type U11 = InstanceType<any>; // any
6666
type U12 = InstanceType<never>; // never
6767
type U13 = InstanceType<string>; // Error
6868
~~~~~~
69-
!!! error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'.
69+
!!! error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any[]) => any'.
7070
type U14 = InstanceType<Function>; // Error
7171
~~~~~~~~
72-
!!! error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'.
73-
!!! error TS2344: Type 'Function' provides no match for the signature 'new (...args: any): any'.
72+
!!! error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any[]) => any'.
73+
!!! error TS2344: Type 'Function' provides no match for the signature 'new (...args: any[]): any'.
7474

7575
type ArgumentType<T extends (x: any) => any> = T extends (a: infer A) => any ? A : any;
7676

tests/baselines/reference/parameterListAsTupleType.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/parameterListAsTupleType.ts(8,17): error TS2322: Type 'string' is not assignable to type 'number'.
2-
tests/cases/compiler/parameterListAsTupleType.ts(16,23): error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any) => any'.
3-
Type 'typeof C' provides no match for the signature '(...args: any): any'.
2+
tests/cases/compiler/parameterListAsTupleType.ts(16,23): error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any[]) => any'.
3+
Type 'typeof C' provides no match for the signature '(...args: any[]): any'.
44

55

66
==== tests/cases/compiler/parameterListAsTupleType.ts (2 errors) ====
@@ -23,8 +23,8 @@ tests/cases/compiler/parameterListAsTupleType.ts(16,23): error TS2344: Type 'typ
2323

2424
type Cps = Parameters<typeof C>; // should not work
2525
~~~~~~~~
26-
!!! error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any) => any'.
27-
!!! error TS2344: Type 'typeof C' provides no match for the signature '(...args: any): any'.
26+
!!! error TS2344: Type 'typeof C' does not satisfy the constraint '(...args: any[]) => any'.
27+
!!! error TS2344: Type 'typeof C' provides no match for the signature '(...args: any[]): any'.
2828
type Ccps = ConstructorParameters<typeof C>; // should be [number, string]
2929

3030
class D {

0 commit comments

Comments
 (0)