Skip to content

v5.5.4 regression "Error: Debug Failure. False expression." when using incremental const x = { ...({} as { [K in keyof { someKey?: any }]?: undefined }) } #60511

@700software

Description

@700software

🔎 Search Terms Description

Ran into this hard to find bug crashing our production build. It was difficult to get a Minimal Reproducible Example for you but after hours of work I finally narrowed it down. Check it out!

Using combination of

  • { "compilerOptions": { "incremental": true } }
  • npm install -D @types/node done after tsconfig.tsbuildinfo already exists
    • Note: This particular sequence is not required for production repro but is the only way I could get this Minimal Reproducible Example for sake of opening this issue. In production, of course, tsconfig.tsbuildinfo is absent on every build to keep things fresh. :)
  • runtime object expansion
  • wrapper type to
    • make properties optional
    • make properties undefined
  • avoid using as const

Am getting crash of typescript build.

Changing any one of these 6 things causes the crash to go away.

🕗 Version & Regression Information

Works fine in 5.5.3
Broken in 5.5.4 & 5.6.3 & 5.7.0-beta

⏯ Playground Link

No repro because incremental checkbox not in playground.

💻 Code

test.ts

type InputType = { enable_member_receipts?: boolean };
type AsEmptyObject<T> = { [K in keyof T]?: undefined }; // This is a utility type we use internally.

const test = {
  // ...

  ...({} as AsEmptyObject<InputType>),
}; // omit `as const`

tsconfig.json

{
  "compilerOptions": {
    "incremental": true,
  }
}

🙁 Actual behavior

PS C:\GitHub\tmp\repro-ts-bug> tsc --noEmit
C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:120986
      throw e;
      ^

Error: Debug Failure. False expression.
    at getOptionalType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:66203:11)
    at tryReuseExistingTypeNode (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:49675:16)
    at serializeTypeForDeclaration (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:51693:61)
    at addPropertyToElementList (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50663:43)
    at createTypeNodesFromResolvedType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50559:11)
    at createTypeNodeFromObjectType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50334:25)
    at visitAndTransformType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50257:24)
    at createAnonymousTypeNode (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50197:20)
    at typeToTypeNodeWorker (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:49990:16)
    at typeToTypeNodeHelper (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:49771:24)

Node.js v22.8.0
PS C:\GitHub\tmp\repro-ts-bug>

🙂 Expected behavior

PS C:\GitHub\tmp\repro-ts-bug> tsc --noEmit
PS C:\GitHub\tmp\repro-ts-bug>

Additional information about the issue

I needed this specific sequence to repro:

PS C:\GitHub\tmp\repro-ts-bug> rm -r -Path node_modules, package.json, package-lock.json, tsconfig.tsbuildinfo
PS C:\GitHub\tmp\repro-ts-bug> npm install -D typescript@5.6.3

added 1 package in 657ms
PS C:\GitHub\tmp\repro-ts-bug> tsc --noEmit
PS C:\GitHub\tmp\repro-ts-bug> npm install @types/node@22.9.0

added 2 packages, and audited 4 packages in 863ms

found 0 vulnerabilities
PS C:\GitHub\tmp\repro-ts-bug> tsc --noEmit
C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:120986
      throw e;
      ^

Error: Debug Failure. False expression.
    at getOptionalType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:66203:11)
    at tryReuseExistingTypeNode (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:49675:16)
    at serializeTypeForDeclaration (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:51693:61)
    at addPropertyToElementList (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50663:43)
    at createTypeNodesFromResolvedType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50559:11)
    at createTypeNodeFromObjectType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50334:25)
    at visitAndTransformType (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50257:24)
    at createAnonymousTypeNode (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:50197:20)
    at typeToTypeNodeWorker (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:49990:16)
    at typeToTypeNodeHelper (C:\GitHub\tmp\repro-ts-bug\node_modules\typescript\lib\tsc.js:49771:24)

Node.js v22.8.0
PS C:\GitHub\tmp\repro-ts-bug>

Replace typescript@5.6.3 with the version you desire to test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions