Skip to content

getTypeListId crashes with TypeError: Cannot read properties of undefined (reading 'id') #59062

Closed
@wasabi315

Description

@wasabi315

🔎 Search Terms

getTypeListId, circular reference, conditional types

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions (confirmed using the Playground)
    • ~3.6.3: does not crash
    • 3.7.5 ~ 3.8.3: throws Debug Failure. False expression.
    • 3.9.7 ~ 5.6.0-dev.20240628: throws TypeError: Cannot read properties of undefined (reading 'id')
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Circularity Errors May Occur In The Presence of Circularities"

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABMAPAfQCoBpFoMoB8AFAJSIDeAsAFCJ2IxhQCmATsAIYTOIByIAWwCCrVhwCeKDImYAPFmAAmAZ0RhBAIzYEZ85ktUixkjDvIBfGvURRxABx4ANRAF4+goxJTO5ClRXNEAH41TTZEAC5QgS1WAgBuGktqIA

💻 Code

function f<_T, _S>() { // The number of type parameters need to be more than 2 to reproduce, strangely
    // Both have to be inside f
    interface NumArray<T extends number> extends Array<T> {}
    type X = NumArray<X extends {} ? number : number>;
}

🙁 Actual behavior

TypeScript throws the following error when type-checking the code above

      throw e;
      ^

TypeError: Cannot read properties of undefined (reading 'id')
    at getTypeListId (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:58078:34)
    at createTypeReference (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:58114:16)
    at createNormalizedTypeReference (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:59115:100)
    at instantiateTypeWorker (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:61599:63)
    at instantiateTypeWithAlias (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:61584:20)
    at instantiateType (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:61562:29)
    at resolveObjectTypeMembers (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:55820:77)
    at resolveTypeReferenceMembers (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:55843:5)
    at resolveStructuredTypeMembers (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:56666:11)
    at getSignaturesOfStructuredType (/Users/wasabi/workspace/typescript/crash/node_modules/typescript/lib/tsc.js:57363:24)

🙂 Expected behavior

For TypeScript not to crash and to display some appropriate error message (such as TS4109).

Additional information about the issue

  • The number parts in the code are probably irrelevant to the issue: we still get the same crash after replacing number to string for example.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions