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
8 changes: 5 additions & 3 deletions tsc/internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3296,13 +3296,15 @@ func (b *NodeBuilderImpl) visitAndTransformType(t *Type, transform func(b *NodeB
isConstructorObject := t.objectFlags&ObjectFlagsAnonymous != 0 && t.symbol != nil && t.symbol.Flags()&ast.SymbolFlagsClass != 0
var id *CompositeSymbolIdentity
switch {
case isArrayOrTuple:
// Do not bound finite container nesting by the shared Array symbol or tuple origin.
id = nil
case t.objectFlags&ObjectFlagsReference != 0 && t.AsTypeReference().node != nil:
// A deferred reference, array and tuple ones included, nests through its
// node, which is how a recursive type nests without end.
id = &CompositeSymbolIdentity{false, 0, ast.GetNodeId(t.AsTypeReference().node)}
case t.flags&TypeFlagsConditional != 0:
id = &CompositeSymbolIdentity{false, 0, ast.GetNodeId(t.AsConditionalType().root.node.AsNode())}
case isArrayOrTuple:
// Do not bound finite container nesting by the shared Array symbol or tuple origin.
id = nil
case t.symbol != nil:
id = &CompositeSymbolIdentity{isConstructorObject, ast.GetSymbolId(t.symbol), 0}
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
expanding.ts(4,14): error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
expanding.ts(5,14): error TS2322: Type '("x" | ((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]' is not assignable to type 'number'.
local.ts(1,17): error TS5088: The inferred type of 'array' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary.
local.ts(5,17): error TS5088: The inferred type of 'tuple' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary.
local.ts(9,17): error TS5088: The inferred type of 'readonlyTuple' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary.
Expand Down Expand Up @@ -45,4 +47,15 @@ local.ts(13,17): error TS5088: The inferred type of 'union' references a type wi
type Nested = number[][][][][][][][][][][][][];
return null as unknown as Nested;
}

==== expanding.ts (2 errors) ====
// Each level is a new instantiation, so printing it stops at a bounded depth.
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.
export const n: number = g;
~
!!! error TS2322: Type '("x" | ((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]' is not assignable to type 'number'.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export function finiteArray() {
return null as unknown as Nested;
}

//// [expanding.ts]
// Each level is a new instantiation, so printing it stops at a bounded depth.
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const h = g;
export const n: number = g;


//// [local.js]
export function array() {
Expand All @@ -57,6 +64,9 @@ export function finite() {
export function finiteArray() {
return null;
}
//// [expanding.js]
export const h = g;
export const n = g;


//// [nameable.d.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ export function finiteArray() {
>Nested : Symbol(Nested, Decl(nameable.ts, 10, 31))
}

=== expanding.ts ===
// Each level is a new instantiation, so printing it stops at a bounded depth.
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
>G : Symbol(G, Decl(expanding.ts, 0, 0))
>T : Symbol(T, Decl(expanding.ts, 1, 7))
>T : Symbol(T, Decl(expanding.ts, 1, 7))
>T : Symbol(T, Decl(expanding.ts, 1, 7))
>G : Symbol(G, Decl(expanding.ts, 0, 0))
>T : Symbol(T, Decl(expanding.ts, 1, 7))

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,19 @@ export function finiteArray() {
>null as unknown : unknown
}

=== expanding.ts ===
// Each level is a new instantiation, so printing it stops at a bounded depth.
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)[])[]

export const h = g;
>h : ("x" | ((((((((((any | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[] | any)[])[]
>g : ("x" | ((((((((((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)[])[]

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

// @filename: local.ts
export function array() {
Expand Down Expand Up @@ -34,3 +35,10 @@ export function finiteArray() {
type Nested = number[][][][][][][][][][][][][];
return null as unknown as Nested;
}

// @filename: expanding.ts
// Each level is a new instantiation, so printing it stops at a bounded depth.
type G<T> = T extends unknown ? (T | G<[T]>)[] : never;
declare const g: G<"x">;
export const h = g;
export const n: number = g;
Loading