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
9 changes: 9 additions & 0 deletions tsc/internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type NodeBuilderContext struct {
inferTypeParameters []*Type
visitedTypes collections.Set[TypeId]
symbolDepth map[CompositeSymbolIdentity]int
containerDepth int
trackedSymbols []*TrackedSymbolArgs
mapper *TypeMapper
reverseMappedStack []*ast.Symbol
Expand Down Expand Up @@ -3245,6 +3246,14 @@ func (b *NodeBuilderImpl) visitAndTransformType(t *Type, transform func(b *NodeB
if b.ctx.visitedTypes.Has(typeId) {
return b.createCyclicStructurePlaceholder()
}
if isArrayOrTuple {
if b.ctx.containerDepth >= 20 {
b.ctx.truncating = true
return b.createElidedInformationPlaceholder()
}
b.ctx.containerDepth++
defer func() { b.ctx.containerDepth-- }()
}

isConstructorObject := t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags&ast.SymbolFlagsClass != 0
var id *CompositeSymbolIdentity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
recursiveArrayTupleDeclarationEmit.ts(3,14): error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.


==== recursiveArrayTupleDeclarationEmit.ts (1 errors) ====
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const h = g;
~
!!! error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

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

//// [recursiveArrayTupleDeclarationEmit.ts]
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const h = g;


//// [recursiveArrayTupleDeclarationEmit.js]
export const h = g;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/recursiveArrayTupleDeclarationEmit.ts] ////

=== recursiveArrayTupleDeclarationEmit.ts ===
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
>G : Symbol(G, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 0))
>T : Symbol(T, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 7))
>T : Symbol(T, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 7))
>T : Symbol(T, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 7))
>G : Symbol(G, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 0))
>T : Symbol(T, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 7))

declare const g: G<"x">;
>g : Symbol(g, Decl(recursiveArrayTupleDeclarationEmit.ts, 1, 13))
>G : Symbol(G, Decl(recursiveArrayTupleDeclarationEmit.ts, 0, 0))

export const h = g;
>h : Symbol(h, Decl(recursiveArrayTupleDeclarationEmit.ts, 2, 12))
>g : Symbol(g, Decl(recursiveArrayTupleDeclarationEmit.ts, 1, 13))

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

=== recursiveArrayTupleDeclarationEmit.ts ===
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
>G : G<T>

declare const g: G<"x">;
>g : ("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]

export const h = g;
>h : ("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]
>g : ("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
recursiveArrayTupleTypePrinting.ts(3,14): error TS2322: Type '("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]' is not assignable to type 'number'.
recursiveArrayTupleTypePrinting.ts(4,14): error TS2322: Type 'string' is not assignable to type 'number'.


==== recursiveArrayTupleTypePrinting.ts (2 errors) ====
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const n: number = g;
~
!!! error TS2322: Type '("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]' is not assignable to type 'number'.
export const later: number = "oops";
~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.

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

=== recursiveArrayTupleTypePrinting.ts ===
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
>G : Symbol(G, Decl(recursiveArrayTupleTypePrinting.ts, 0, 0))
>T : Symbol(T, Decl(recursiveArrayTupleTypePrinting.ts, 0, 7))
>T : Symbol(T, Decl(recursiveArrayTupleTypePrinting.ts, 0, 7))
>T : Symbol(T, Decl(recursiveArrayTupleTypePrinting.ts, 0, 7))
>G : Symbol(G, Decl(recursiveArrayTupleTypePrinting.ts, 0, 0))
>T : Symbol(T, Decl(recursiveArrayTupleTypePrinting.ts, 0, 7))

declare const g: G<"x">;
>g : Symbol(g, Decl(recursiveArrayTupleTypePrinting.ts, 1, 13))
>G : Symbol(G, Decl(recursiveArrayTupleTypePrinting.ts, 0, 0))

export const n: number = g;
>n : Symbol(n, Decl(recursiveArrayTupleTypePrinting.ts, 2, 12))
>g : Symbol(g, Decl(recursiveArrayTupleTypePrinting.ts, 1, 13))

export const later: number = "oops";
>later : Symbol(later, Decl(recursiveArrayTupleTypePrinting.ts, 3, 12))

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

=== recursiveArrayTupleTypePrinting.ts ===
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
>G : G<T>

declare const g: G<"x">;
>g : ("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]

export const n: number = g;
>n : number
>g : ("x" | (((((((((((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]

export const later: number = "oops";
>later : number
>"oops" : "oops"

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

type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const h = g;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @strict: true
// @noErrorTruncation: true
// @noEmit: true

type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const n: number = g;
export const later: number = "oops";
Loading