Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
inferFromTypeArgumentsNoInfiniteRecursion.ts(34,10): error TS2589: Type instantiation is excessively deep and possibly infinite.


==== inferFromTypeArgumentsNoInfiniteRecursion.ts (1 errors) ====
// Repro from #64701
// Checking `ReturnType<typeof createHandler>` relates the generic signature of
// `createHandler` to the signature in the `extends` clause of `ReturnType`, which
// instantiates it in the context of that signature. Inferring between the type
// arguments of nested instantiations of the same type aliases used to recurse
// through inferFromTypes and inferFromTypeArguments without terminating.

type IsEqual<A, B> =
(<G>() => G extends A & G | G ? 1 : 2) extends
(<G>() => G extends B & G | G ? 1 : 2)
? true
: false;

type Fn = (...args: any) => any;
type Next<TFn extends Fn, TStack extends Fn> = (...args: Parameters<TStack & TFn>) => ReturnType<TStack & TFn>;
type Wrap<TFn extends Fn> = TFn extends unknown ? TFn : () => void;

type Inner<TFn extends Fn, TAcc extends Fn, TStack extends Fn, TPrevious extends Fn, TCurrent extends Fn = Next<TFn, TStack>> =
IsEqual<TCurrent, TPrevious> extends true ? TAcc : Inner<TFn, TAcc & Wrap<TCurrent>, TCurrent & TStack, TCurrent>;

type OwnProperties<T> = { [K in keyof T]: T[K] };
type Unwrap<TFn> = TFn extends Fn ? TFn : TFn;

type Tree<T> = T extends Fn
? Unwrap<Inner<T, Wrap<T>, T, T>> & Tree<OwnProperties<T>>
: T;

interface Client<T> {
call: Tree<T>;
}

declare function createHandler<T extends Fn>(): Client<T>;

type R = ReturnType<typeof createHandler>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.

Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//// [tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts] ////

=== inferFromTypeArgumentsNoInfiniteRecursion.ts ===
// Repro from #64701
// Checking `ReturnType<typeof createHandler>` relates the generic signature of
// `createHandler` to the signature in the `extends` clause of `ReturnType`, which
// instantiates it in the context of that signature. Inferring between the type
// arguments of nested instantiations of the same type aliases used to recurse
// through inferFromTypes and inferFromTypeArguments without terminating.

type IsEqual<A, B> =
>IsEqual : Symbol(IsEqual, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 0, 0))
>A : Symbol(A, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 7, 13))
>B : Symbol(B, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 7, 15))

(<G>() => G extends A & G | G ? 1 : 2) extends
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 8, 6))
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 8, 6))
>A : Symbol(A, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 7, 13))
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 8, 6))
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 8, 6))

(<G>() => G extends B & G | G ? 1 : 2)
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 9, 6))
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 9, 6))
>B : Symbol(B, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 7, 15))
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 9, 6))
>G : Symbol(G, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 9, 6))

? true
: false;

type Fn = (...args: any) => any;
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>args : Symbol(args, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 13, 11))

type Next<TFn extends Fn, TStack extends Fn> = (...args: Parameters<TStack & TFn>) => ReturnType<TStack & TFn>;
>Next : Symbol(Next, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 13, 32))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 10))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TStack : Symbol(TStack, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 25))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>args : Symbol(args, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 48))
>Parameters : Symbol(Parameters, Decl(lib.es5.d.ts, --, --))
>TStack : Symbol(TStack, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 25))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 10))
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --))
>TStack : Symbol(TStack, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 25))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 10))

type Wrap<TFn extends Fn> = TFn extends unknown ? TFn : () => void;
>Wrap : Symbol(Wrap, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 111))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 15, 10))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 15, 10))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 15, 10))

type Inner<TFn extends Fn, TAcc extends Fn, TStack extends Fn, TPrevious extends Fn, TCurrent extends Fn = Next<TFn, TStack>> =
>Inner : Symbol(Inner, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 15, 67))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 11))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TAcc : Symbol(TAcc, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 26))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TStack : Symbol(TStack, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 43))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TPrevious : Symbol(TPrevious, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 62))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TCurrent : Symbol(TCurrent, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 84))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>Next : Symbol(Next, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 13, 32))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 11))
>TStack : Symbol(TStack, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 43))

IsEqual<TCurrent, TPrevious> extends true ? TAcc : Inner<TFn, TAcc & Wrap<TCurrent>, TCurrent & TStack, TCurrent>;
>IsEqual : Symbol(IsEqual, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 0, 0))
>TCurrent : Symbol(TCurrent, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 84))
>TPrevious : Symbol(TPrevious, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 62))
>TAcc : Symbol(TAcc, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 26))
>Inner : Symbol(Inner, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 15, 67))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 11))
>TAcc : Symbol(TAcc, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 26))
>Wrap : Symbol(Wrap, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 111))
>TCurrent : Symbol(TCurrent, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 84))
>TCurrent : Symbol(TCurrent, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 84))
>TStack : Symbol(TStack, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 43))
>TCurrent : Symbol(TCurrent, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 17, 84))

type OwnProperties<T> = { [K in keyof T]: T[K] };
>OwnProperties : Symbol(OwnProperties, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 18, 118))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 19))
>K : Symbol(K, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 27))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 19))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 19))
>K : Symbol(K, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 27))

type Unwrap<TFn> = TFn extends Fn ? TFn : TFn;
>Unwrap : Symbol(Unwrap, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 49))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 12))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 12))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 12))
>TFn : Symbol(TFn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 12))

type Tree<T> = T extends Fn
>Tree : Symbol(Tree, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 46))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))

? Unwrap<Inner<T, Wrap<T>, T, T>> & Tree<OwnProperties<T>>
>Unwrap : Symbol(Unwrap, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 20, 49))
>Inner : Symbol(Inner, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 15, 67))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))
>Wrap : Symbol(Wrap, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 14, 111))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))
>Tree : Symbol(Tree, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 46))
>OwnProperties : Symbol(OwnProperties, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 18, 118))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))

: T;
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 23, 10))

interface Client<T> {
>Client : Symbol(Client, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 25, 8))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 27, 17))

call: Tree<T>;
>call : Symbol(Client.call, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 27, 21))
>Tree : Symbol(Tree, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 21, 46))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 27, 17))
}

declare function createHandler<T extends Fn>(): Client<T>;
>createHandler : Symbol(createHandler, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 29, 1))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 31, 31))
>Fn : Symbol(Fn, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 11, 16))
>Client : Symbol(Client, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 25, 8))
>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 31, 31))

type R = ReturnType<typeof createHandler>;
>R : Symbol(R, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 31, 58))
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --))
>createHandler : Symbol(createHandler, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 29, 1))

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//// [tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts] ////

=== inferFromTypeArgumentsNoInfiniteRecursion.ts ===
// Repro from #64701
// Checking `ReturnType<typeof createHandler>` relates the generic signature of
// `createHandler` to the signature in the `extends` clause of `ReturnType`, which
// instantiates it in the context of that signature. Inferring between the type
// arguments of nested instantiations of the same type aliases used to recurse
// through inferFromTypes and inferFromTypeArguments without terminating.

type IsEqual<A, B> =
>IsEqual : IsEqual<A, B>

(<G>() => G extends A & G | G ? 1 : 2) extends
(<G>() => G extends B & G | G ? 1 : 2)
? true
>true : true

: false;
>false : false

type Fn = (...args: any) => any;
>Fn : Fn
>args : any

type Next<TFn extends Fn, TStack extends Fn> = (...args: Parameters<TStack & TFn>) => ReturnType<TStack & TFn>;
>Next : Next<TFn, TStack>
>args : Parameters<TStack & TFn>

type Wrap<TFn extends Fn> = TFn extends unknown ? TFn : () => void;
>Wrap : Wrap<TFn>

type Inner<TFn extends Fn, TAcc extends Fn, TStack extends Fn, TPrevious extends Fn, TCurrent extends Fn = Next<TFn, TStack>> =
>Inner : Inner<TFn, TAcc, TStack, TPrevious, TCurrent>

IsEqual<TCurrent, TPrevious> extends true ? TAcc : Inner<TFn, TAcc & Wrap<TCurrent>, TCurrent & TStack, TCurrent>;
>true : true

type OwnProperties<T> = { [K in keyof T]: T[K] };
>OwnProperties : OwnProperties<T>

type Unwrap<TFn> = TFn extends Fn ? TFn : TFn;
>Unwrap : Unwrap<TFn>

type Tree<T> = T extends Fn
>Tree : Tree<T>

? Unwrap<Inner<T, Wrap<T>, T, T>> & Tree<OwnProperties<T>>
: T;

interface Client<T> {
call: Tree<T>;
>call : Tree<T>
}

declare function createHandler<T extends Fn>(): Client<T>;
>createHandler : <T extends Fn>() => Client<T>

type R = ReturnType<typeof createHandler>;
>R : Client<Fn>
>createHandler : <T extends Fn>() => Client<T>

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @target: es2015
// @strict: true
// @noEmit: true

// Repro from #64701
// Checking `ReturnType<typeof createHandler>` relates the generic signature of
// `createHandler` to the signature in the `extends` clause of `ReturnType`, which
// instantiates it in the context of that signature. Inferring between the type
// arguments of nested instantiations of the same type aliases used to recurse
// through inferFromTypes and inferFromTypeArguments without terminating.

type IsEqual<A, B> =
(<G>() => G extends A & G | G ? 1 : 2) extends
(<G>() => G extends B & G | G ? 1 : 2)
? true
: false;

type Fn = (...args: any) => any;
type Next<TFn extends Fn, TStack extends Fn> = (...args: Parameters<TStack & TFn>) => ReturnType<TStack & TFn>;
type Wrap<TFn extends Fn> = TFn extends unknown ? TFn : () => void;

type Inner<TFn extends Fn, TAcc extends Fn, TStack extends Fn, TPrevious extends Fn, TCurrent extends Fn = Next<TFn, TStack>> =
IsEqual<TCurrent, TPrevious> extends true ? TAcc : Inner<TFn, TAcc & Wrap<TCurrent>, TCurrent & TStack, TCurrent>;

type OwnProperties<T> = { [K in keyof T]: T[K] };
type Unwrap<TFn> = TFn extends Fn ? TFn : TFn;

type Tree<T> = T extends Fn
? Unwrap<Inner<T, Wrap<T>, T, T>> & Tree<OwnProperties<T>>
: T;

interface Client<T> {
call: Tree<T>;
}

declare function createHandler<T extends Fn>(): Client<T>;

type R = ReturnType<typeof createHandler>;
Loading