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

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

Open
700software opened this issue Nov 15, 2024 · 1 comment

Comments

@700software
Copy link

700software commented Nov 15, 2024

🔎 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 [email protected]

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

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 [email protected] with the version you desire to test.

@700software 700software changed the title v5.6.3 regression "Error: Debug Failure. False expression." when using incremental + @types/node + const x = { ...({} as { [K in keyof { someKey?: any }]?: undefined }) } v5.6.3 regression "Error: Debug Failure. False expression." when using incremental const x = { ...({} as { [K in keyof { someKey?: any }]?: undefined }) } Nov 15, 2024
@700software 700software changed the title v5.6.3 regression "Error: Debug Failure. False expression." when using incremental const x = { ...({} as { [K in keyof { someKey?: any }]?: undefined }) } v5.5.4 regression "Error: Debug Failure. False expression." when using incremental const x = { ...({} as { [K in keyof { someKey?: any }]?: undefined }) } Nov 15, 2024
@Andarist
Copy link
Contributor

Andarist commented Nov 15, 2024

duplicate of #60390

fourslash test:

// @strictNullChecks: false
// @declaration: true
// @emitDeclarationOnly: true

type InputType = { enable_member_receipts?: boolean };
type AsEmptyObject<T> = { [K in keyof T]?: undefined };

export const test = {
  ...({} as AsEmptyObject<InputType>),
};

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

2 participants