Skip to content

Stack overflow in recursive type #20772

Description

@evmar

TypeScript Version: playground, [email protected]
Code

type Recur = () => Recur.B;

Expected behavior:
Compile error.

Actual behavior:
Stack overflow.

.../node_modules/typescript/lib/tsc.js:59609
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at resolveEntityName (.../node_modules/typescript/lib/tsc.js:20834:35)
    at resolveEntityName (.../node_modules/typescript/lib/tsc.js:20859:33)
    at resolveTypeReferenceName (.../node_modules/typescript/lib/tsc.js:25382:20)
    at getTypeFromTypeReference (.../node_modules/typescript/lib/tsc.js:25481:30)
    at getTypeFromTypeNode (.../node_modules/typescript/lib/tsc.js:26360:28)
    at getSignatureReturnTypeFromDeclaration (.../node_modules/typescript/lib/tsc.js:24997:24)
    at getSignatureFromDeclaration (.../node_modules/typescript/lib/tsc.js:24964:34)
    at getSignaturesOfSymbol (.../node_modules/typescript/lib/tsc.js:25062:37)
    at resolveAnonymousTypeMembers (.../node_modules/typescript/lib/tsc.js:24311:38)
    at resolveStructuredTypeMembers (.../node_modules/typescript/lib/tsc.js:24458:25)

Activity

  1. DanielRosenwasser commented on Dec 19, 2017

    @DanielRosenwasser
    Member

    Doesn't show up until TypeScript 2.5. This is probably my fault from #17459.

  2. DanielRosenwasser commented on Dec 19, 2017

    @DanielRosenwasser
    Member

    But actually, this is a symptom of a different issue, so it's really a good thing I did that.

    Here's a more direct repro that doesn't only exhibit the stack overflow from trying to give a more helpful error message:

    type Recur = () => Recur['B']
  3. sandersn commented on Dec 21, 2017

    @sandersn
    Member

    Fixed by #20400

    Structured type resolution did not previously care about recursive type resolution; it was only handled in specific cases. Recursive resolution can happen almost anywhere now, so #20400 changes resolveStructuredTypeMembers to handle it.

  4. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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