Skip to content
Draft
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
3 changes: 3 additions & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21508,6 +21508,9 @@ func (c *Checker) instantiateTypeWithAlias(t *Type, m *TypeMapper, alias *TypeAl
// or expression. There is a very high likelihood we're dealing with a combination of infinite generic types
// that perpetually generate new type identities, so we stop the recursion here by yielding the error type.
c.error(c.currentNode, diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite)
// Set this to a max value to "propagate" the error through any further instantiations within the currently checked node.
// This can skip a bunch of redundant work in the case of hitting the depth limit.
c.instantiationCount = 5_000_000
return c.errorType
}
index := c.findActiveMapper(m)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
recursiveConditionalCrash5.ts(13,6): error TS2589: Type instantiation is excessively deep and possibly infinite.


==== recursiveConditionalCrash5.ts (1 errors) ====
// https://github.com/microsoft/TypeScript/issues/63269

type Prepend<Elm, T extends unknown[]> = T extends unknown
? ((arg: Elm, ...rest: T) => void) extends (...args: infer T2) => void
? T2
: never
: never;

type ExactExtract<T, U> = (T extends U ? U extends T ? T : never : never) & string;

type Conv<T, U = T> = {
0: [T];
1: Prepend<T, Conv<ExactExtract<U, T>>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
}[U extends T ? 0 : 1];

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

=== recursiveConditionalCrash5.ts ===
// https://github.com/microsoft/TypeScript/issues/63269

type Prepend<Elm, T extends unknown[]> = T extends unknown
>Prepend : Symbol(Prepend, Decl(recursiveConditionalCrash5.ts, 0, 0))
>Elm : Symbol(Elm, Decl(recursiveConditionalCrash5.ts, 2, 13))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 2, 17))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 2, 17))

? ((arg: Elm, ...rest: T) => void) extends (...args: infer T2) => void
>arg : Symbol(arg, Decl(recursiveConditionalCrash5.ts, 3, 6))
>Elm : Symbol(Elm, Decl(recursiveConditionalCrash5.ts, 2, 13))
>rest : Symbol(rest, Decl(recursiveConditionalCrash5.ts, 3, 15))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 2, 17))
>args : Symbol(args, Decl(recursiveConditionalCrash5.ts, 3, 46))
>T2 : Symbol(T2, Decl(recursiveConditionalCrash5.ts, 3, 60))

? T2
>T2 : Symbol(T2, Decl(recursiveConditionalCrash5.ts, 3, 60))

: never
: never;

type ExactExtract<T, U> = (T extends U ? U extends T ? T : never : never) & string;
>ExactExtract : Symbol(ExactExtract, Decl(recursiveConditionalCrash5.ts, 6, 10))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 8, 18))
>U : Symbol(U, Decl(recursiveConditionalCrash5.ts, 8, 20))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 8, 18))
>U : Symbol(U, Decl(recursiveConditionalCrash5.ts, 8, 20))
>U : Symbol(U, Decl(recursiveConditionalCrash5.ts, 8, 20))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 8, 18))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 8, 18))

type Conv<T, U = T> = {
>Conv : Symbol(Conv, Decl(recursiveConditionalCrash5.ts, 8, 83))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 10, 10))
>U : Symbol(U, Decl(recursiveConditionalCrash5.ts, 10, 12))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 10, 10))

0: [T];
>0 : Symbol(0, Decl(recursiveConditionalCrash5.ts, 10, 23))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 10, 10))

1: Prepend<T, Conv<ExactExtract<U, T>>>;
>1 : Symbol(1, Decl(recursiveConditionalCrash5.ts, 11, 9))
>Prepend : Symbol(Prepend, Decl(recursiveConditionalCrash5.ts, 0, 0))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 10, 10))
>Conv : Symbol(Conv, Decl(recursiveConditionalCrash5.ts, 8, 83))
>ExactExtract : Symbol(ExactExtract, Decl(recursiveConditionalCrash5.ts, 6, 10))
>U : Symbol(U, Decl(recursiveConditionalCrash5.ts, 10, 12))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 10, 10))

}[U extends T ? 0 : 1];
>U : Symbol(U, Decl(recursiveConditionalCrash5.ts, 10, 12))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 10, 10))

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

=== recursiveConditionalCrash5.ts ===
// https://github.com/microsoft/TypeScript/issues/63269

type Prepend<Elm, T extends unknown[]> = T extends unknown
>Prepend : Prepend<Elm, T>

? ((arg: Elm, ...rest: T) => void) extends (...args: infer T2) => void
>arg : Elm
>rest : T
>args : T2

? T2
: never
: never;

type ExactExtract<T, U> = (T extends U ? U extends T ? T : never : never) & string;
>ExactExtract : ExactExtract<T, U>

type Conv<T, U = T> = {
>Conv : Conv<T, U>

0: [T];
>0 : [T]

1: Prepend<T, Conv<ExactExtract<U, T>>>;
>1 : Prepend<T, Conv<ExactExtract<U, T>, ExactExtract<U, T>>>

}[U extends T ? 0 : 1];

17 changes: 17 additions & 0 deletions testdata/tests/cases/compiler/recursiveConditionalCrash5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/63269

type Prepend<Elm, T extends unknown[]> = T extends unknown
? ((arg: Elm, ...rest: T) => void) extends (...args: infer T2) => void
? T2
: never
: never;

type ExactExtract<T, U> = (T extends U ? U extends T ? T : never : never) & string;

type Conv<T, U = T> = {
0: [T];
1: Prepend<T, Conv<ExactExtract<U, T>>>;
}[U extends T ? 0 : 1];