Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDOC @type tag crashes with simple export #36830

Closed
rchl opened this issue Feb 17, 2020 · 3 comments
Closed

JSDOC @type tag crashes with simple export #36830

rchl opened this issue Feb 17, 2020 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@rchl
Copy link
Contributor

rchl commented Feb 17, 2020

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:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 10, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Mar 10, 2020
@orta
Copy link
Contributor

orta commented Apr 1, 2020

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?

@orta
Copy link
Contributor

orta commented Apr 1, 2020

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

@orta orta added the Fix Available A PR has been opened for this issue label May 4, 2020
@orta orta added the Rescheduled This issue was previously scheduled to an earlier milestone label May 12, 2020
@orta orta modified the milestones: TypeScript 3.9.1, TypeScript 4.0 May 12, 2020
pastelmind added a commit to pastelmind/d2calc that referenced this issue Jul 17, 2020
Using import("assert").strict appears to cause TypeScript to enter an
infinite loop. This prevented type checking from working properly in the
test suite.

Workaround: Add 'typeof' at the beginning of the @type annotation.

Possibly related issue:
  microsoft/TypeScript#36830
@orta orta removed their assignment Jul 21, 2020
@RyanCavanaugh RyanCavanaugh assigned orta and unassigned sandersn Aug 18, 2020
@RyanCavanaugh RyanCavanaugh removed the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 18, 2020
@orta
Copy link
Contributor

orta commented Aug 18, 2020

A fix for this got merged yesterday: #39770

@orta orta closed this as completed Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants