Skip to content

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

@mmvsk

Description

@mmvsk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions