Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ...args: never in builtin conditional type helpers #55714

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1603,17 +1603,17 @@ type NonNullable<T> = T & {};
/**
* Obtain the parameters of a function type in a tuple
*/
type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
type Parameters<T extends (...args: never) => any> = T extends (...args: infer P) => any ? P : never;

/**
* Obtain the parameters of a constructor function type in a tuple
*/
type ConstructorParameters<T extends abstract new (...args: any) => any> = T extends abstract new (...args: infer P) => any ? P : never;
type ConstructorParameters<T extends abstract new (...args: never) => any> = T extends abstract new (...args: infer P) => any ? P : never;

/**
* Obtain the return type of a function type
*/
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
type ReturnType<T extends (...args: never) => any> = T extends (...args: never) => infer R ? R : any;

/**
* Obtain the return type of a constructor function type
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/unittests/tsc/incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ console.log(a);`,
fs,
"/lib/lib.d.ts",
Utils.dedent`
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;`,
type ReturnType<T extends (...args: never) => any> = T extends (...args: never) => infer R ? R : any;
type InstanceType<T extends abstract new (...args: never) => any> = T extends abstract new (...args: never) => infer R ? R : any;`,
),
edits: [
{
Expand Down
96 changes: 48 additions & 48 deletions tests/baselines/reference/constraintWithIndexedAccess.errors.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
constraintWithIndexedAccess.ts(23,90): error TS2344: Type 'TypeHardcodedAsParameterWithoutReturnType<T, F>' does not satisfy the constraint '(...args: any) => any'.
Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T][string]' is not assignable to type '(...args: any) => any'.
constraintWithIndexedAccess.ts(24,102): error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: any) => any'.
Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T][string]' is not assignable to type '(...args: any) => any'.
constraintWithIndexedAccess.ts(26,103): error TS2344: Type 'VehicleSelector<T>[F]' does not satisfy the constraint '(...args: any) => any'.
Type 'VehicleSelector<T>[keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
Type 'VehicleSelector<T>[string] | VehicleSelector<T>[number] | VehicleSelector<T>[symbol]' is not assignable to type '(...args: any) => any'.
Type 'VehicleSelector<T>[string]' is not assignable to type '(...args: any) => any'.
constraintWithIndexedAccess.ts(27,102): error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: any) => any'.
Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T][string]' is not assignable to type '(...args: any) => any'.
constraintWithIndexedAccess.ts(28,102): error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'.
Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: any) => any'.
constraintWithIndexedAccess.ts(23,90): error TS2344: Type 'TypeHardcodedAsParameterWithoutReturnType<T, F>' does not satisfy the constraint '(...args: never) => any'.
Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T][string]' is not assignable to type '(...args: never) => any'.
constraintWithIndexedAccess.ts(24,102): error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: never) => any'.
Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T][string]' is not assignable to type '(...args: never) => any'.
constraintWithIndexedAccess.ts(26,103): error TS2344: Type 'VehicleSelector<T>[F]' does not satisfy the constraint '(...args: never) => any'.
Type 'VehicleSelector<T>[keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
Type 'VehicleSelector<T>[string] | VehicleSelector<T>[number] | VehicleSelector<T>[symbol]' is not assignable to type '(...args: never) => any'.
Type 'VehicleSelector<T>[string]' is not assignable to type '(...args: never) => any'.
constraintWithIndexedAccess.ts(27,102): error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: never) => any'.
Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T][string]' is not assignable to type '(...args: never) => any'.
constraintWithIndexedAccess.ts(28,102): error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: never) => any'.
Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: never) => any'.
constraintWithIndexedAccess.ts(28,102): error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'.
constraintWithIndexedAccess.ts(29,102): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'.
constraintWithIndexedAccess.ts(29,102): error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'.
Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[F][string]' is not assignable to type '(...args: any) => any'.
Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: any) => any'.
constraintWithIndexedAccess.ts(29,102): error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: never) => any'.
Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[F][string]' is not assignable to type '(...args: never) => any'.
Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: never) => any'.
constraintWithIndexedAccess.ts(29,102): error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'.


Expand Down Expand Up @@ -52,45 +52,45 @@ constraintWithIndexedAccess.ts(29,102): error TS2536: Type 'F' cannot be used to
export type SucceedingCombo = ReturnType<TypeHardcodedAsParameterWithoutReturnType<'Boat', keyof DataFetchFns['Boat']>>;
export type FailingCombo<T extends 'Boat', F extends keyof DataFetchFns[T]> = ReturnType<TypeHardcodedAsParameterWithoutReturnType<T,F>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type 'TypeHardcodedAsParameterWithoutReturnType<T, F>' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'TypeHardcodedAsParameterWithoutReturnType<T, F>' does not satisfy the constraint '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string]' is not assignable to type '(...args: never) => any'.
export type TypeHardcodedAsParameter<T extends 'Boat', F extends keyof DataFetchFns[T]> = ReturnType<DataFetchFns[T][F]>;
~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string]' is not assignable to type '(...args: never) => any'.
type VehicleSelector<T extends keyof DataFetchFns> = DataFetchFns[T];
export type TypeHardcodedAsParameter2<T extends 'Boat', F extends keyof DataFetchFns[T]> = ReturnType<VehicleSelector<T>[F]>;
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type 'VehicleSelector<T>[F]' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[string] | VehicleSelector<T>[number] | VehicleSelector<T>[symbol]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[string]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[F]' does not satisfy the constraint '(...args: never) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[string] | VehicleSelector<T>[number] | VehicleSelector<T>[symbol]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'VehicleSelector<T>[string]' is not assignable to type '(...args: never) => any'.
export type TypeGeneric1<T extends keyof DataFetchFns, F extends keyof DataFetchFns[T]> = ReturnType<DataFetchFns[T][F]>;
~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][F]' does not satisfy the constraint '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string] | DataFetchFns[T][number] | DataFetchFns[T][symbol]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T][string]' is not assignable to type '(...args: never) => any'.
export type TypeGeneric2<T extends keyof DataFetchFns, F extends keyof DataFetchFns[T]> = ReturnType<DataFetchFns[T][T]>; // error
~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[T][T]' does not satisfy the constraint '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T]["Boat"] | DataFetchFns[T]["Plane"]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[T]["Boat"]' is not assignable to type '(...args: never) => any'.
~~~~~~~~~~~~~~~~~~
!!! error TS2536: Type 'T' cannot be used to index type 'DataFetchFns[T]'.
export type TypeGeneric3<T extends keyof DataFetchFns, F extends keyof DataFetchFns[T]> = ReturnType<DataFetchFns[F][F]>; // error
~~~~~~~~~~~~~~~
!!! error TS2536: Type 'F' cannot be used to index type 'DataFetchFns'.
~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[F][string]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: any) => any'.
!!! error TS2344: Type 'DataFetchFns[F][F]' does not satisfy the constraint '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[F][keyof DataFetchFns[T]]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[F][string] | DataFetchFns[F][number] | DataFetchFns[F][symbol]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[F][string]' is not assignable to type '(...args: never) => any'.
!!! error TS2344: Type 'DataFetchFns[keyof DataFetchFns[T]][string]' is not assignable to type '(...args: never) => any'.
~~~~~~~~~~~~~~~~~~
!!! error TS2536: Type 'F' cannot be used to index type 'DataFetchFns[F]'.

8 changes: 4 additions & 4 deletions tests/baselines/reference/genericRestParameters1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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'.
genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: never) => any'.
Type 'Function' provides no match for the signature '(...args: never): any'.
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'.
Expand Down Expand Up @@ -142,8 +142,8 @@ genericRestParameters1.ts(164,1): error TS2322: Type '(a: never) => void' is not
type T08<T extends any[]> = ConstructorParameters<new (...args: T) => void>;
type T09 = Parameters<Function>;
~~~~~~~~
!!! 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: never) => any'.
!!! error TS2344: Type 'Function' provides no match for the signature '(...args: never): any'.

type Record1 = {
move: [number, 'left' | 'right'];
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/inferTypes1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inferTypes1.ts(36,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'.
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'.
inferTypes1.ts(36,23): error TS2344: Type 'string' does not satisfy the constraint '(...args: never) => any'.
inferTypes1.ts(37,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: never) => any'.
Type 'Function' provides no match for the signature '(...args: never): any'.
inferTypes1.ts(43,25): error TS2344: Type 'string' does not satisfy the constraint 'abstract new (...args: any) => any'.
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'.
Expand Down Expand Up @@ -59,11 +59,11 @@ inferTypes1.ts(153,40): error TS2322: Type 'T' is not assignable to type 'string
type T16 = ReturnType<never>; // never
type T17 = ReturnType<string>; // Error
~~~~~~
!!! error TS2344: Type 'string' does not satisfy the constraint '(...args: any) => any'.
!!! error TS2344: Type 'string' does not satisfy the constraint '(...args: never) => any'.
type T18 = ReturnType<Function>; // 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: never) => any'.
!!! error TS2344: Type 'Function' provides no match for the signature '(...args: never): any'.
type T19<T extends any[]> = ReturnType<(x: string, ...args: T) => T[]>; // T[]

type U10 = InstanceType<typeof C>; // C
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/inferTypesBuiltinHelpers.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/conformance/types/conditional/inferTypesBuiltinHelpers.ts] ////

=== inferTypesBuiltinHelpers.ts ===
// https://github.com/microsoft/TypeScript/issues/55667

type _1 = ReturnType<(...args: never) => 'foo'>
>_1 : Symbol(_1, Decl(inferTypesBuiltinHelpers.ts, 0, 0))
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --))
>args : Symbol(args, Decl(inferTypesBuiltinHelpers.ts, 2, 22))

type _2 = InstanceType<new (...args: never) => 'foo'>
>_2 : Symbol(_2, Decl(inferTypesBuiltinHelpers.ts, 2, 47))
>InstanceType : Symbol(InstanceType, Decl(lib.es5.d.ts, --, --))
>args : Symbol(args, Decl(inferTypesBuiltinHelpers.ts, 3, 28))

Loading