Skip to content

Crash: RangeError: Maximum call stack size exceeded in containsReference when a generic ImportType has malformed arguments in a nested conditional #62952

@na7ure-a

Description

@na7ure-a

🔎 Search Terms

RangeError: Maximum call stack size exceeded

containsReference stack overflow

ImportType malformed generic crash

Circularity check crash nested conditional

🕗 Version & Regression Information

Versions tested: 5.7.3, 5.8.3, 5.9.3, Nightly

Behavior: All tested versions crash.

Key Trigger: A generic type from an import() call is used inside a nested conditional type, but the generic arguments are missing or syntactically invalid (e.g., import("./name").Name instead of import("./name").Name).

⏯ Playground Link

https://www.typescriptlang.org/zh/play/?target=7&ts=6.0.0-dev.20260104#code/PTAEGIGYEYA4CYAsAoZJQAEBmBLANgKYB2AhgLYEBcopFAdAC4DOyBAHgA4D2ATg6AwCeHAqABy5AgB4AKgD5QAXlAkiggNyp02fMUnUcRACbtGLISNAypADQXLVg0OwbEjTUAApPj521fGHr4A-CpqoNRMDDyGAOYAlH4B7mFOoThk3HyeAER0wLQEOfF0EhTUjvHIoKChjtURqZpAA

💻 Code

// #31824

// @filename: name.ts
export type Name<T> = any;

// @filename: index.ts
type T<X> = any extends ((any extends any ? any : string) extends any ? import("./name").Name: any)
  ? any
  : any;

🙁 Actual behavior

.\ts-versions\nightly\node_modules\.bin\tsc.cmd    C:\Users\aw\Desktop\corpus\nestedGenericConditionalTypeWithGenericImportType.ts
D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:123181
      throw e;
      ^

RangeError: Maximum call stack size exceeded
    at forEachChild (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28725:22)                                                                                                    
    at containsReference (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:63412:16)                                                                                               
    at visitNode2 (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28209:18)                                                                                                      
    at forEachChildInLiteralType (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28355:12)                                                                                       
    at forEachChild (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28730:35)                                                                                                    
    at containsReference (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:63412:16)                                                                                               
    at visitNode2 (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28209:18)                                                                                                      
    at forEachChildInImportType (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28341:12)                                                                                        
    at forEachChild (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:28730:35)                                                                                                    
    at containsReference (D:\do\typeFuzz\ts-versions\nightly\node_modules\typescript\lib\_tsc.js:63412:16)                                                                                               

Node.js v22.19.0

🙂 Expected behavior

The compiler should not crash.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions