Skip to content

Circular reference in default type parameter crashes compiler #16221

Closed
@jcalz

Description

@jcalz

TypeScript Version: 2.3 and up

Code

class SelfReference<T = SelfReference<string>> {}

Expected behavior:
The compiler either accepts it (so that new SelfReference() has the type SelfReference<SelfReference<string>>) or rejects it (by explicitly disallowing a circular reference in default type parameters).

Actual behavior:
The compiler goes into an infinite loop that exceeds the recursion limit:

RangeError: Maximum call stack size exceeded
  at resolveNameHelper (typescript\lib\typescript.js:26480:35)
  at resolveName (typescript\lib\typescript.js:26478:20)
  at resolveEntityName (typescript\lib\typescript.js:27128:26)
  at getTypeFromTypeReference (typescript\lib\typescript.js:31874:54)
  at getTypeFromTypeNode (typescript\lib\typescript.js:32724:28)
  at getDefaultFromTypeParameter (typescript\lib\typescript.js:31032:66)
⋮

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions