Skip to content

Repro of huge spike tsc memory usage from 5.5.4 -> 5.6.2 #62660

@AlexeiDarmin-SA

Description

@AlexeiDarmin-SA

🔎 Search Terms

TSC Memory bump from 5.5.4 to 5.6.2 - one issue closed #60166

🕗 Version & Regression Information

  • This changed between versions 5.5.4 and 5.6.2
  • This changed in commit or PR N/A
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about N/A
  • I was unable to test this on prior versions because N/A

⏯ Playground Link

https://github.com/AlexeiDarmin-SA/ts-memory-repro

💻 Code

Reproduce the error The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed with the following snippet:

function wrap<T>(x: T) { return { top: x, right: x, bottom: x, left: x }; }

// 9–10 wraps is usually enough. If it doesn't fail at 9, try 10 or 11.
export const box =
  wrap(wrap(wrap(wrap(wrap(wrap(wrap(wrap(wrap("x"))))))))); // 9 wraps

Approach taken from Medium article, it's behind a paywall :(

Core idea:

Discover through a simple 51-character example how and why a TypeScript type explodes to 2,000,000 and breaks your build

🙁 Actual behavior

TSC memory usage doubled to 540kb when running the following command in Typescript v5.6.2 in the repro repo.

yarn tsc -p tsconfig.app.json --declaration --emitDeclarationOnly --extendedDiagnostics`
Image

In a real world example for a private repo I saw memory go 5x from 4GB to 20GB.

🙂 Expected behavior

Expected memory usage to remain unaffected when running the command at 270KB

Image

Additional information about the issue

One other thread discussed this and was closed due to lacking repro steps: #60166

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions