Skip to content
Open
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
11 changes: 10 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23707,7 +23707,9 @@ func (n *TupleNormalizer) normalize(c *Checker, elementTypes []*Type, elementInf
if info.flags&ElementFlagsVariadic != 0 {
if t.flags&TypeFlagsAny != 0 {
n.add(t, TupleElementInfo{flags: ElementFlagsRest, labeledDeclaration: info.labeledDeclaration})
} else if t.flags&TypeFlagsInstantiableNonPrimitive != 0 || c.isGenericMappedType(t) {
} else if someContainedType(t, func(t *Type) bool {
return t.flags&TypeFlagsInstantiableNonPrimitive != 0 || c.isGenericMappedType(t)
}) {
// Generic variadic elements stay as they are.
n.add(t, info)
} else if isTupleType(t) {
Expand Down Expand Up @@ -26893,6 +26895,13 @@ func everyType(t *Type, f func(*Type) bool) bool {
return f(t)
}

func someContainedType(t *Type, f func(*Type) bool) bool {
if t.flags&TypeFlagsUnionOrIntersection != 0 {
return core.Some(t.Types(), f)
}
return f(t)
}

func everyContainedType(t *Type, f func(*Type) bool) bool {
if t.flags&TypeFlagsUnionOrIntersection != 0 {
return core.Every(t.Types(), f)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
recursiveConditionalCrash5.ts(3,60): error TS2589: Type instantiation is excessively deep and possibly infinite.


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

type StringTreeArrayAsTuple<T> = (T extends [...infer R] ? [...StringTreeArrayAsTuple<R>] : never) & boolean;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.

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

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

type StringTreeArrayAsTuple<T> = (T extends [...infer R] ? [...StringTreeArrayAsTuple<R>] : never) & boolean;
>StringTreeArrayAsTuple : Symbol(StringTreeArrayAsTuple, Decl(recursiveConditionalCrash5.ts, 0, 0))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 2, 28))
>T : Symbol(T, Decl(recursiveConditionalCrash5.ts, 2, 28))
>R : Symbol(R, Decl(recursiveConditionalCrash5.ts, 2, 53))
>StringTreeArrayAsTuple : Symbol(StringTreeArrayAsTuple, Decl(recursiveConditionalCrash5.ts, 0, 0))
>R : Symbol(R, Decl(recursiveConditionalCrash5.ts, 2, 53))

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

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

type StringTreeArrayAsTuple<T> = (T extends [...infer R] ? [...StringTreeArrayAsTuple<R>] : never) & boolean;
>StringTreeArrayAsTuple : StringTreeArrayAsTuple<T>

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

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

type StringTreeArrayAsTuple<T> = (T extends [...infer R] ? [...StringTreeArrayAsTuple<R>] : never) & boolean;