diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 6f6f4c493009a..b8ae7ca57efa9 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1508,7 +1508,7 @@ type Parameters any> = T extends (...args: infer P) /** * 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 abstract new (...args: infer P) => any ? P : never; /** * Obtain the return type of a function type @@ -1518,7 +1518,7 @@ type ReturnType any> = T extends (...args: any) => i /** * 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 abstract new (...args: any) => infer R ? R : any; /** * Convert string literal type to uppercase diff --git a/tests/baselines/reference/inferTypes1.errors.txt b/tests/baselines/reference/inferTypes1.errors.txt index d1ab94f7af991..82f384705352b 100644 --- a/tests/baselines/reference/inferTypes1.errors.txt +++ b/tests/baselines/reference/inferTypes1.errors.txt @@ -1,13 +1,9 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(36,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'. tests/cases/conformance/types/conditional/inferTypes1.ts(37,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(43,25): error TS2344: Type 'string' does not satisfy the constraint 'new (...args: any) => any'. -tests/cases/conformance/types/conditional/inferTypes1.ts(44,25): error TS2344: Type 'Function' does not satisfy the constraint 'new (...args: any) => any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(43,25): error TS2344: Type 'string' does not satisfy the constraint 'abstract new (...args: any) => any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(44,25): error TS2344: Type 'Function' does not satisfy the constraint 'abstract new (...args: any) => any'. Type 'Function' provides no match for the signature 'new (...args: any): any'. -tests/cases/conformance/types/conditional/inferTypes1.ts(45,25): error TS2344: Type 'typeof Abstract' does not satisfy the constraint 'new (...args: any) => any'. - Cannot assign an abstract constructor type to a non-abstract constructor type. -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'. - Cannot assign an abstract constructor type to a non-abstract constructor type. 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'. tests/cases/conformance/types/conditional/inferTypes1.ts(56,25): error TS2344: Type 'Function' does not satisfy the constraint '(x: any) => any'. 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: Type 'T' is not assignable to type 'symbol'. -==== tests/cases/conformance/types/conditional/inferTypes1.ts (18 errors) ==== +==== tests/cases/conformance/types/conditional/inferTypes1.ts (16 errors) ==== type Unpacked = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : @@ -75,20 +71,14 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(153,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 'abstract 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' does not satisfy the constraint 'abstract new (...args: any) => any'. !!! error TS2344: Type 'Function' provides no match for the signature 'new (...args: any): any'. type U15 = InstanceType; // Abstract - ~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'typeof Abstract' does not satisfy the constraint 'new (...args: any) => any'. -!!! error TS2344: Cannot assign an abstract constructor type to a non-abstract constructor type. type U16 = InstanceType T[]>; // T[] type U17 = InstanceType T[]>; // T[] - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2344: Type 'abstract new (x: string, ...args: T) => T[]' does not satisfy the constraint 'new (...args: any) => any'. -!!! error TS2344: Cannot assign an abstract constructor type to a non-abstract constructor type. type ArgumentType any> = T extends (a: infer A) => any ? A : any; diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types index 86b0b145fb6b3..4ef817304b407 100644 --- a/tests/baselines/reference/inferTypes1.types +++ b/tests/baselines/reference/inferTypes1.types @@ -117,7 +117,7 @@ type U14 = InstanceType; // Error >U14 : any type U15 = InstanceType; // Abstract ->U15 : any +>U15 : Abstract >Abstract : typeof Abstract type U16 = InstanceType T[]>; // T[] @@ -126,7 +126,7 @@ type U16 = InstanceType T[]>; / >args : T type U17 = InstanceType T[]>; // T[] ->U17 : any +>U17 : T[] >x : string >args : T