TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Fix compiler crash on generics overload resolution failure

Open moznion opened this issue 1 month ago • 7 comments

Fixes #61524

Replace Debug.fail() calls with proper error generation to prevent TypeScript compiler crashes when overload resolution fails for complex generic constraints, for example JSX elements.

Problem

The TypeScript compiler crashes with "Debug Failure. No error for last overload signature" when resolving certain complex generic constraints, e.g., JSX element types. This regression has existed since TypeScript 3.6 and affects many React/JSX projects.

Root Cause

When getSignatureApplicabilityError() returns no diagnostics for overload candidates, the compiler calls Debug.fail() instead of handling the edge case gracefully, causing an immediate crash.

Solution

  • Replace Debug.fail() calls with fallback diagnostic generation
  • Generate appropriate error messages for unhandled overload resolution cases
  • Ensure compiler continues execution without crashing

Note

This change doesn’t fix the core logic of type inference. Ideally, that core should be fixed, but this pull request only addresses the compiler crash.

Related to #61524, #60229, #48636, #33133

moznion avatar Nov 21 '25 06:11 moznion

@microsoft-github-policy-service agree

moznion avatar Nov 21 '25 06:11 moznion

I think this is just papering over a bug somewhere else. IIRC the intent of these debug fails are to assert that the previous steps added an error.

jakebailey avatar Dec 02 '25 00:12 jakebailey

@jakebailey Thank you for your comment. Are you saying that the core issue lies in type inference, or somewhere else? It makes sense from a language-processor perspective, but in our project the crash occurs during type checking, and it has been blocking us from upgrading from v5.6.3; this suggests the problem first appeared in v5.7.

moznion avatar Dec 04 '25 06:12 moznion

If it's a regression, I would consider bisecting with https://www.npmjs.com/package/every-ts

jakebailey avatar Dec 04 '25 06:12 jakebailey

I don't think this is a regression. It appears that the problem still occurs on the latest main branch.

moznion avatar Dec 04 '25 10:12 moznion

But you said it wasn't broken in 5.5, so there is a commit in between where this broke.

jakebailey avatar Dec 04 '25 15:12 jakebailey

But, https://github.com/microsoft/TypeScript/issues/61524#issuecomment-2780342066 seems to imply there's already a PR for this?

jakebailey avatar Dec 04 '25 15:12 jakebailey