Skip to content

Compiler crash on some functions with self-referential types #52757

@garybernhardt

Description

@garybernhardt

Bug Report

🔎 Search Terms

"Maximum call stack size exceeded". There are many issues referencing this, but most seem like different bugs from this, and I don't see any that have a simple repro like I provide here.

🕗 Version & Regression Information

I tested in these versions:

  • Untestable in 4.6.4 and earlier (the repro code causes a syntax error)
  • Fails in 4.7.4.
  • Fails in 4.8.4.
  • Fails in 4.9.5 (current release as of this report)
  • Fails in 5.0.0-dev.20230214 (current "next" as of this report)

⏯ Playground Link

Playground link with relevant code Load it up, hit "Run", then look at your browser's dev console to see that the compiler blew the stack.

💻 Code

function f<T>(args: typeof f<T>):T { return args; }

🙁 Actual behavior

The compiler itself throws RangeError: Maximum call stack size exceeded. E.g.:

$ cat temp.ts
function f<T>(args: typeof f<T>):T { return args; }
$ npx tsc temp.ts
/Users/grb/proj/execprog/node_modules/typescript/lib/tsc.js:99612
                throw e;
                ^

RangeError: Maximum call stack size exceeded

🙂 Expected behavior

The code either compiles or gives a type error.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions