Skip to content

An assertion over a large union of string literals never finishes #65620

Open

Description

@magurotuna

TypeScript Version

The tested TypeScript version is 7.1.0-dev.20261120.1. 5.9.3 behaves the same, but slower.

OS: macOS 26.7 (arm64). Times are rough, because the machine ran other work at the same time.

User Goal

The user tests type checking of Vue files through content mappers on open-source projects. On one project, the check did not finish, and the user asked me to find out why. The trigger is code that the Vue content mapper generates (a fix is in review in vuejs/language-tools#6317), and a reduced TypeScript-only version also hangs.

Setup and Action

repro.ts:

type D = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
type Key = `k.${D}${D}${D}${"0" | "1" | "2" | "3"}`; // 4,000 string literals

declare function assertBox<T>(t: T): asserts t is NonNullable<T> & { value: T };
declare const key: Key | undefined;
assertBox(key);
key.value;

Run tsc --strict --noEmit --extendedDiagnostics repro.ts.

Expected and Actual Behavior

What actually happened: the check does not finish. The time grows about 4 times when the number of literals in Key doubles:

Literals 7.1.0-dev 5.9.3
1,000 1.2 s 5.6 s
2,000 4.9 s 19.8 s
4,000 did not finish in 120 s did not finish in 240 s

What I expected: a time similar to asserts t is NonNullable<T> (without & { value: T }), which takes 0.55 s for 4,000 literals.

After 60 s, a goroutine dump (SIGQUIT) of 7.1.0-dev shows the checker in getNarrowedTypeWorker → isTypeStrictSubtypeOf → checkTypeRelatedToEx → reportDiagnostic → DiagnosticsCollection.Add → EqualDiagnostics. Possibly related: #63854.

In the project where this was found (openobserve, about 31,000 literals), the check with 7.1.0-beta did not finish in 12 minutes.

Agent Info

Claude Code 2.1.317 + Claude Opus 5.5 + Skill Version 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: Performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions