Skip to content

JSDOC @type tag crashes with simple export #36830

Closed

Description

TypeScript Version: 3.9.0-dev.20200215 (also tested 3.7.5)

(the last one that doesn't crash is v3.7.1-rc. v3.7.2 crashes)

Search Terms:

Maximum call stack size exceeded
getTypeOfFuncClassEnumModule

Code

/lib/index.js:

/** @type {import('../types/index').xxx} */
function xxx() {
    return null;
}

/types/index.d.ts:

export function xxx(): string;

/tsconfig.json:

{
    "compilerOptions": {
        "target": "esnext",
        "module": "commonjs",
        "esModuleInterop": true,
        "lib": [
            "dom",
            "esnext"
        ],
        "allowJs": true,
        "checkJs": true,
        "noEmit": true,
        "resolveJsonModule": true,
        "strict": true,
        "moduleResolution": "node",
        "baseUrl": ".",
    }
}

Expected behavior:

No crash.
Typescript error about function returning wrong error type.

Actual behavior:

Crash.

/me/ts-crash-test/node_modules/typescript/lib/tsc.js:81193
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at getSymbolLinks (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:28829:32)
    at getTypeOfFuncClassEnumModule (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:33936:25)
    at getTypeOfSymbol (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:34045:24)
    at getTypeFromJSDocValueReference (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36634:33)
    at getTypeReferenceType (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36620:33)
    at getTypeFromJSDocValueReference (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36648:36)
    at getTypeReferenceType (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36620:33)
    at getTypeFromJSDocValueReference (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36648:36)
    at getTypeReferenceType (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36620:33)
    at getTypeFromJSDocValueReference (/me/ts-crash-test/node_modules/typescript/lib/tsc.js:36648:36)

Playground Link:

https://github.com/rchl/ts-crash-test

Related Issues:

Activity

  1. orta commented on Apr 1, 2020

    @orta
    Contributor

    Cool, reproduced with:

    // @allowJs: true
    // @noEmit: true
    // @checkJs: true
    
    // @filename: lib/index.js
    /** @type {import('../folder/index').zzz} */
    function xxx() {
      return null;
    }
    
    // @filename: folder/index.d.ts
    export function zzz(): string;

    In normal TypeScript code, you wouldn't write import('../folder/index').zzz - but would write typeof import('../folder/index').zzz to get to the type () => string - doing this doesn't cause the loop in the code.

    Which I think leads to another question, what should be the behavior here in JSDoc world? Do we assume we want the typeof to be assumed because you're using @type or does it still represent the export-ed identifier of zzz?

  2. orta commented on Apr 1, 2020

    @orta
    Contributor

    Asked around, and the opinion is yes - we want to pretend there's a typeof before the import in this case - gonna pair on it next week

  3. added 3 commits that reference this issue on May 4, 2020
    0fe7acc
    3f5726e
    97db3b5
  4. added
    Fix Available
    on May 4, 2020
  5. added
    Rescheduled
    on May 12, 2020
  6. added a commit that references this issue on Jul 17, 2020
  7. removed their assignment
    on Jul 21, 2020
  8. removed
    Rescheduled
    on Aug 18, 2020
  9. orta commented on Aug 18, 2020

    @orta
    Contributor

    A fix for this got merged yesterday: #39770

  10. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugFix Available

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ Proxy