diff --git a/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.errors.txt b/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.errors.txt new file mode 100644 index 0000000000000..d5528df2bff4f --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.errors.txt @@ -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` 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 = + (() => G extends A & G | G ? 1 : 2) extends + (() => G extends B & G | G ? 1 : 2) + ? true + : false; + + type Fn = (...args: any) => any; + type Next = (...args: Parameters) => ReturnType; + type Wrap = TFn extends unknown ? TFn : () => void; + + type Inner> = + IsEqual extends true ? TAcc : Inner, TCurrent & TStack, TCurrent>; + + type OwnProperties = { [K in keyof T]: T[K] }; + type Unwrap = TFn extends Fn ? TFn : TFn; + + type Tree = T extends Fn + ? Unwrap, T, T>> & Tree> + : T; + + interface Client { + call: Tree; + } + + declare function createHandler(): Client; + + type R = ReturnType; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.symbols b/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.symbols new file mode 100644 index 0000000000000..00ffe3a2b8b81 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.symbols @@ -0,0 +1,146 @@ +//// [tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts] //// + +=== inferFromTypeArgumentsNoInfiniteRecursion.ts === +// Repro from #64701 +// Checking `ReturnType` 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 = +>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 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 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 = (...args: Parameters) => ReturnType; +>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 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> = +>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 extends true ? TAcc : Inner, 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 = { [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 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 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, T, T>> & Tree> +>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 { +>Client : Symbol(Client, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 25, 8)) +>T : Symbol(T, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 27, 17)) + + call: Tree; +>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(): Client; +>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; +>R : Symbol(R, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 31, 58)) +>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --)) +>createHandler : Symbol(createHandler, Decl(inferFromTypeArgumentsNoInfiniteRecursion.ts, 29, 1)) + diff --git a/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.types b/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.types new file mode 100644 index 0000000000000..e6a37e60e2e59 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/inferFromTypeArgumentsNoInfiniteRecursion.types @@ -0,0 +1,62 @@ +//// [tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts] //// + +=== inferFromTypeArgumentsNoInfiniteRecursion.ts === +// Repro from #64701 +// Checking `ReturnType` 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 = +>IsEqual : IsEqual + + (() => G extends A & G | G ? 1 : 2) extends + (() => G extends B & G | G ? 1 : 2) + ? true +>true : true + + : false; +>false : false + +type Fn = (...args: any) => any; +>Fn : Fn +>args : any + +type Next = (...args: Parameters) => ReturnType; +>Next : Next +>args : Parameters + +type Wrap = TFn extends unknown ? TFn : () => void; +>Wrap : Wrap + +type Inner> = +>Inner : Inner + + IsEqual extends true ? TAcc : Inner, TCurrent & TStack, TCurrent>; +>true : true + +type OwnProperties = { [K in keyof T]: T[K] }; +>OwnProperties : OwnProperties + +type Unwrap = TFn extends Fn ? TFn : TFn; +>Unwrap : Unwrap + +type Tree = T extends Fn +>Tree : Tree + + ? Unwrap, T, T>> & Tree> + : T; + +interface Client { + call: Tree; +>call : Tree +} + +declare function createHandler(): Client; +>createHandler : () => Client + +type R = ReturnType; +>R : Client +>createHandler : () => Client + diff --git a/tsc/testdata/tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts b/tsc/testdata/tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts new file mode 100644 index 0000000000000..7352bbdd20f44 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/inferFromTypeArgumentsNoInfiniteRecursion.ts @@ -0,0 +1,38 @@ +// @target: es2015 +// @strict: true +// @noEmit: true + +// Repro from #64701 +// Checking `ReturnType` 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 = + (() => G extends A & G | G ? 1 : 2) extends + (() => G extends B & G | G ? 1 : 2) + ? true + : false; + +type Fn = (...args: any) => any; +type Next = (...args: Parameters) => ReturnType; +type Wrap = TFn extends unknown ? TFn : () => void; + +type Inner> = + IsEqual extends true ? TAcc : Inner, TCurrent & TStack, TCurrent>; + +type OwnProperties = { [K in keyof T]: T[K] }; +type Unwrap = TFn extends Fn ? TFn : TFn; + +type Tree = T extends Fn + ? Unwrap, T, T>> & Tree> + : T; + +interface Client { + call: Tree; +} + +declare function createHandler(): Client; + +type R = ReturnType;