TypeScript: Debug Failure. Unhandled Diagnostic: 2626

Bug Report

Regression in v4.2.1-rc (EDIT: also an issue in v4.2.2), tsc fails to compile with an error Debug Failure. Unhandled Diagnostic: 2626. It worked fine in v4.2.0-beta

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions v4.2.1-beta and v4.2.2-rc
  • This is the behaviour in every version I tried, and I reviewed the FAQ for entries about β€œDebug Failure. Unhandled Diagnostic: 2626”
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// I don't have a simple reproduction, this occurs in our ~60,000 SLOC codebase which is 50% Javascript using checkJs mode

tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "es2020"],
    "allowJs": true,
    "checkJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noFallthroughCasesInSwitch": true,

    "downlevelIteration": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "noImplicitAny": false,
    "baseUrl": "src"
  },
  "include": ["src"],

  "exclude": ["cypress", "src/**/__tests__/*.test.*"],
  "typeAcquisition": {
    "include": ["jest"],
    "exclude": ["chai", "cypress"]
  }
}

πŸ™ Actual behaviour

TSC crashes and fails to compile

$ yarn tsc --extendedDiagnostics

...\node_modules\typescript\lib\tsc.js:88040
                throw e;
                ^

Error: Debug Failure. Unhandled Diagnostic: 2626
    at reportIncompatibleStack (...\node_modules\typescript\lib\tsc.js:49104:45)
    at checkTypeRelatedTo (...\node_modules\typescript\lib\tsc.js:48976:17)
    at checkTypeRelatedToAndOptionallyElaborate (...\node_modules\typescript\lib\tsc.js:48255:24)
    at checkTypeAssignableToAndOptionallyElaborate (...\node_modules\typescript\lib\tsc.js:48249:20)
    at checkVariableLikeDeclaration (...\node_modules\typescript\lib\tsc.js:62811:25)
    at checkVariableDeclaration (...\node_modules\typescript\lib\tsc.js:62876:13)
    at checkSourceElementWorker (...\node_modules\typescript\lib\tsc.js:65151:28)
    at checkSourceElement (...\node_modules\typescript\lib\tsc.js:64999:17)
    at Object.forEach (...\node_modules\typescript\lib\tsc.js:128:30)
    at checkVariableStatement (...\node_modules\typescript\lib\tsc.js:62886:16)

πŸ™‚ Expected behaviour

It should compile, which worked in v4.2 beta

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 14
  • Comments: 21 (2 by maintainers)

Most upvoted comments

@stevehollaar any chance you could share code that reproduces the issue? That would help us out a ton

Unfortunately the codebase is proprietary and I wasn’t able to isolate a small repro.

I ended up debugging this by adding a console.log line:

console.log({source, sourceType });

in tsc.js, just prior to this line:

reportIncompatibleError(ts.Diagnostics.Type_at_position_0_in_source_is_not_compatible_with_type_at_position_1_in_target, sourceIndex, i);

That gave me:

{
  source: Type {
    flags: 524288,
    id: 117489,
    symbol: undefined,
    objectFlags: 1114116,
    target: <ref *1> Type {
      flags: 524288,
      id: 1048,
      objectFlags: 12,
      symbol: undefined,
      members: undefined,
      properties: undefined,
      callSignatures: undefined,
      constructSignatures: undefined,
      stringIndexInfo: undefined,
      numberIndexInfo: undefined,
      typeParameters: [Array],
      outerTypeParameters: undefined,
      localTypeParameters: [Array],
      instantiations: [Map],
      target: [Circular *1],
      resolvedTypeArguments: [Array],
      thisType: [Type],
      declaredProperties: [Array],
      declaredCallSignatures: [],
      declaredConstructSignatures: [],
      declaredStringIndexInfo: undefined,
      declaredNumberIndexInfo: undefined,
      elementFlags: [Array],
      minLength: 2,
      fixedLength: 2,
      hasRestElement: false,
      combinedFlags: 1,
      readonly: false,
      labeledElementDeclarations: undefined,
      resolvedBaseTypes: [Array],
      baseTypesResolved: true
    },
    resolvedTypeArguments: [ [Type], [Type] ],
    members: Map(36) {
      '0' => [Symbol],
      '1' => [Symbol],
      'length' => [Symbol],
      'toString' => [Symbol],
      'toLocaleString' => [Symbol],
      'pop' => [Symbol],
      'push' => [Symbol],
      'concat' => [Symbol],
      'join' => [Symbol],
      'reverse' => [Symbol],
      'shift' => [Symbol],
      'slice' => [Symbol],
      'sort' => [Symbol],
      'splice' => [Symbol],
      'unshift' => [Symbol],
      'indexOf' => [Symbol],
      'lastIndexOf' => [Symbol],
      'every' => [Symbol],
      'some' => [Symbol],
      'forEach' => [Symbol],
      'map' => [Symbol],
      'filter' => [Symbol],
      'reduce' => [Symbol],
      'reduceRight' => [Symbol],
      'find' => [Symbol],
      'findIndex' => [Symbol],
      'fill' => [Symbol],
      'copyWithin' => [Symbol],
      '__@iterator' => [Symbol],
      'entries' => [Symbol],
      'keys' => [Symbol],
      'values' => [Symbol],
      '__@unscopables' => [Symbol],
      'includes' => [Symbol],
      'flatMap' => [Symbol],
      'flat' => [Symbol]
    },
    properties: [
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol],
      [Symbol], [Symbol], [Symbol], [Symbol]
    ],
    callSignatures: [],
    constructSignatures: [],
    stringIndexInfo: undefined,
    numberIndexInfo: { type: [Type], isReadonly: false, declaration: [Node] }
  },
  sourceType: Type {
    flags: 524288,
    id: 117487,
    objectFlags: 16,
    symbol: Symbol {
      flags: 4096,
      escapedName: '__object',
      declarations: [Array],
      valueDeclaration: [Node],
      id: undefined,
      mergeId: undefined,
      parent: undefined,
      members: [Map]
    },
    members: Map(3) {
      'notificationId' => [Symbol],
      'getTemplateData' => [Symbol],
      'generateStartEndDate' => [Symbol]
    },
    properties: [ [Symbol], [Symbol], [Symbol] ],
    callSignatures: [],
    constructSignatures: [],
    stringIndexInfo: undefined,
    numberIndexInfo: undefined
  }
}

just prior to the tsc error, and from there I was able to find the problematic code via the sourceType.members.

I think there must have been something funky about the way types were shared across module boundaries (possibly related to a circular reference?), as when I tried to repro in the playground, I could not. My β€œfix” was to explicitly type some exported objects with a shared interface, instead of leaving the type as implicit. I hope this helps!