Skip to content

Commit e10a325

Browse files
authored
Use 'abstract new' in InstanceType and ConstructorParameters (#43380)
1 parent fbd7f7d commit e10a325

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/lib/es5.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ type Parameters<T extends (...args: any) => any> = T extends (...args: infer P)
15081508
/**
15091509
* Obtain the parameters of a constructor function type in a tuple
15101510
*/
1511-
type ConstructorParameters<T extends new (...args: any) => any> = T extends new (...args: infer P) => any ? P : never;
1511+
type ConstructorParameters<T extends abstract new (...args: any) => any> = T extends abstract new (...args: infer P) => any ? P : never;
15121512

15131513
/**
15141514
* Obtain the return type of a function type
@@ -1518,7 +1518,7 @@ type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => i
15181518
/**
15191519
* Obtain the return type of a constructor function type
15201520
*/
1521-
type InstanceType<T extends new (...args: any) => any> = T extends new (...args: any) => infer R ? R : any;
1521+
type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;
15221522

15231523
/**
15241524
* Convert string literal type to uppercase

tests/baselines/reference/inferTypes1.errors.txt

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
tests/cases/conformance/types/conditional/inferTypes1.ts(36,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'.
22
tests/cases/conformance/types/conditional/inferTypes1.ts(37,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'.
33
Type 'Function' provides no match for the signature '(...args: any): any'.
4-
tests/cases/conformance/types/conditional/inferTypes1.ts(43,25): error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'.
5-
tests/cases/conformance/types/conditional/inferTypes1.ts(44,25): error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'.
4+
tests/cases/conformance/types/conditional/inferTypes1.ts(43,25): error TS2344: Type 'string' does not satisfy the constraint 'abstract new (...args: any) => any'.
5+
tests/cases/conformance/types/conditional/inferTypes1.ts(44,25): error TS2344: Type 'Function' does not satisfy the constraint 'abstract new (...args: any) => any'.
66
Type 'Function' provides no match for the signature 'new (...args: any): any'.
7-
tests/cases/conformance/types/conditional/inferTypes1.ts(45,25): error TS2344: Type 'typeof Abstract' does not satisfy the constraint 'new (...args: any) => any'.
8-
Cannot assign an abstract constructor type to a non-abstract constructor type.
9-
tests/cases/conformance/types/conditional/inferTypes1.ts(47,42): error TS2344: Type 'abstract new (x: string, ...args: T) => T[]' does not satisfy the constraint 'new (...args: any) => any'.
10-
Cannot assign an abstract constructor type to a non-abstract constructor type.
117
tests/cases/conformance/types/conditional/inferTypes1.ts(55,25): error TS2344: Type '(x: string, y: string) => number' does not satisfy the constraint '(x: any) => any'.
128
tests/cases/conformance/types/conditional/inferTypes1.ts(56,25): error TS2344: Type 'Function' does not satisfy the constraint '(x: any) => any'.
139
Type 'Function' provides no match for the signature '(x: any): any'.
@@ -25,7 +21,7 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(153,40): error TS2322:
2521
Type 'T' is not assignable to type 'symbol'.
2622

2723

28-
==== tests/cases/conformance/types/conditional/inferTypes1.ts (18 errors) ====
24+
==== tests/cases/conformance/types/conditional/inferTypes1.ts (16 errors) ====
2925
type Unpacked<T> =
3026
T extends (infer U)[] ? U :
3127
T extends (...args: any[]) => infer U ? U :
@@ -75,20 +71,14 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(153,40): error TS2322:
7571
type U12 = InstanceType<never>; // never
7672
type U13 = InstanceType<string>; // Error
7773
~~~~~~
78-
!!! error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'.
74+
!!! error TS2344: Type 'string' does not satisfy the constraint 'abstract new (...args: any) => any'.
7975
type U14 = InstanceType<Function>; // Error
8076
~~~~~~~~
81-
!!! error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'.
77+
!!! error TS2344: Type 'Function' does not satisfy the constraint 'abstract new (...args: any) => any'.
8278
!!! error TS2344: Type 'Function' provides no match for the signature 'new (...args: any): any'.
8379
type U15 = InstanceType<typeof Abstract>; // Abstract
84-
~~~~~~~~~~~~~~~
85-
!!! error TS2344: Type 'typeof Abstract' does not satisfy the constraint 'new (...args: any) => any'.
86-
!!! error TS2344: Cannot assign an abstract constructor type to a non-abstract constructor type.
8780
type U16<T extends any[]> = InstanceType<new (x: string, ...args: T) => T[]>; // T[]
8881
type U17<T extends any[]> = InstanceType<abstract new (x: string, ...args: T) => T[]>; // T[]
89-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90-
!!! error TS2344: Type 'abstract new (x: string, ...args: T) => T[]' does not satisfy the constraint 'new (...args: any) => any'.
91-
!!! error TS2344: Cannot assign an abstract constructor type to a non-abstract constructor type.
9282

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

tests/baselines/reference/inferTypes1.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ type U14 = InstanceType<Function>; // Error
117117
>U14 : any
118118

119119
type U15 = InstanceType<typeof Abstract>; // Abstract
120-
>U15 : any
120+
>U15 : Abstract
121121
>Abstract : typeof Abstract
122122

123123
type U16<T extends any[]> = InstanceType<new (x: string, ...args: T) => T[]>; // T[]
@@ -126,7 +126,7 @@ type U16<T extends any[]> = InstanceType<new (x: string, ...args: T) => T[]>; /
126126
>args : T
127127

128128
type U17<T extends any[]> = InstanceType<abstract new (x: string, ...args: T) => T[]>; // T[]
129-
>U17 : any
129+
>U17 : T[]
130130
>x : string
131131
>args : T
132132

0 commit comments

Comments
 (0)