Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript 4.5 Beta infinite loop leading to JS heap out of memory #689

Closed
mmvsk opened this issue Oct 5, 2021 · 5 comments
Closed

Typescript 4.5 Beta infinite loop leading to JS heap out of memory #689

mmvsk opened this issue Oct 5, 2021 · 5 comments

Comments

@mmvsk
Copy link

mmvsk commented Oct 5, 2021

An issue appeared with TypeScript 4.5.0-dev.20211001 that made tsc go into an infinite loop leading to an out-of-memory error.

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["es2020"]
  },
  "exclude": ["node_modules"],
  "include": ["run.ts"]
}

package.json:

{
  "type": "commonjs",
  "scripts": {
    "start": "tsc -p ."
  },
  "dependencies": {
    "zod": "^3.9.8"
  },
  "devDependencies": {
    "typescript": "^4.5.0-beta"
  }

when using tsc directly, the following import cause the issue:

import { z } from "zod";

when using ts-node instead of tsc, this is the minimum necessary code to cause the issue:

import { z } from "zod";

const schema: z.ZodSchema<string> = z.string();

Demo code in: https://github.com/mmvsk/bug-zod-typescript-4.5.0-oct-01

The same code works until TypeScript 4.5.0-dev.20210930, and the issue was probably introduced with the following TypeScript PR: microsoft/TypeScript#41821

@MikeRippon
Copy link

For reference, there's another issue here, which I think is probably tracking the same issue (?)

@mmvsk
Copy link
Author

mmvsk commented Oct 10, 2021

It's not the same, as Zod was working with TS 4.3, 4.4, and 4.5 until 4.5.0-dev.20210930 (included).

There was a pretty large refactoring in TypeScript PR microsoft/TypeScript#41821, and by quickly looking at the diff and the scope of that PR (refactoring recursion-related code) it may very well have introduced this kind of regression.

However, I don't know if Zod is using a faulty behavior of TS that was fixed in 4.5.0-dev.20211001, or if it's a real new TS issue.

@mmvsk
Copy link
Author

mmvsk commented Oct 10, 2021

I just tried on a blank setup (Mac M1, without node previously installed), same issue.

Better to figure this out before TS 4.5 is released.

@mmvsk
Copy link
Author

mmvsk commented Oct 19, 2021

Well, there is progress.

TypeScript was fixed (in microsoft/TypeScript#46326), so now we have a clear error message instead of a memory error.

I created a new issue #715.

@mmvsk mmvsk closed this as completed Oct 19, 2021
@colinhacks
Copy link
Owner

Happy to see that fix land. I struggled to solve that issue for most of Saturday and made minimal progress. The DeepPartial thing is a much easier fix, I'll look into it when I have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants