question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular reference error happens in jsdoc but not in typescript.

See original GitHub issue

Bug Report

🔎 Search Terms

circularly references itself jsdoc ts2456

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about circular

⏯ Playground Link

Playground link (js) Playground link (ts)

💻 Code

Foo.js

/** @typedef {Object.<string, Foo>} Foo */

Foo.ts

type Foo = {
    [x: string]: Foo;
};

🙁 Actual behavior

Type alias 'Foo' circularly references itself. ts(2456) happens in Foo.js. The TypeScript equivalent works fine.

🙂 Expected behavior

Both Foo.ts and Foo.js work without errors.

Related issues

I found some related issues but they are either closed or use a different example. #39372 - Closed (fixed) #45641 - Seems very similar but uses Array<> and typescript rather than jsdoc. I’m not sure if the root cause is the same so this might be a duplicate.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

4reactions
jespertheendcommented, Apr 26, 2022

The workaround is to use TypeScript in the JSDoc comment, rather than Object.<string, Foo> notation:

/**
 * @typedef {{
 *  [x: string]: Foo
 * }} Foo
 */

(playground)

3reactions
jespertheendcommented, Apr 26, 2022

Seems like that’s because Json[] is also in there. Another way to work around this is to add an extra type just for the array:

/**
 * @typedef {null | boolean | number | string | JsonArray | {[property: string]: Json}} Json
 */

/** @typedef {Json[]} JsonArray */

(playground)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular reference error happens in jsdoc but not in typescript ...
Type alias 'Foo' circularly references itself. ts(2456) happens in Foo.js . The TypeScript equivalent works fine. Expected behavior. Both Foo.
Read more >
Using `import type` statement to fix circular dependency ...
The example above will create a circular reference which currently does not work in the JavaScript runtime I'm using. The file B.js really...
Read more >
Documentation - Project References - TypeScript
Project references are a new feature in TypeScript 3.0 that allow you to structure your TypeScript programs into smaller pieces.
Read more >
The reasons I don't use Typescript - DEV Community ‍ ‍
There really is no "I want to learn just enough JSDoc TS" - you've got to ... But of course such error will...
Read more >
API with NestJS #61. Dealing with circular dependencies
A circular dependency between Node.js modules happens when two files ... import/no-cycle, and it ensures that no circular dependencies are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found