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.

Declaration files built from JSDoc typedefs with optional parameters reference indirect dependency

See original GitHub issue

Bug Report

🔎 Search Terms

jsdoc declaration files optional parameters .d.ts grandchild indirect dependency

🕗 Version & Regression Information

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

⏯ Playground Link

Can’t provide TypeScript playground because I don’t see an option to build JSDoc types. But I did create a contained repo.

💻 Code

child/index.js:

/**
 * @typedef {import('grandchild').Options} Options
 */

parent/index.js:

/**
 * @typedef PluginOptions
 * @property {import('child').Options} [childOptions]
 */

🙁 Actual behavior

parent/index.js compiles to:

export type PluginOptions = {
    childOptions?: import("grandchild").Options | undefined;
};

This causes problem because parent doesn’t have a direct dependency on grandchild

🙂 Expected behavior

parent/index.js compiles to:

export type PluginOptions = {
    childOptions?: import("child").Options | undefined;
};

Note that this works correctly if childOptions is not optional. As in, this:

/**
 * @typedef PluginOptions
 * @property {import('child').Options} childOptions
 */

Correctly compiles to:

export type PluginOptions = {
    childOptions: import('child').Options;
};

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Methuselah96commented, Mar 14, 2022

I’m not expecting the declaration emitter to re-export any symbols, I’m expecting it recognize that it can’t reuse the underlying type if the underlying type uses an import since it might not have access to that dependency.

0reactions
Methuselah96commented, Mar 15, 2022

In this case it’s invalid to use the originating declaration because it’s trying to import a package that it doesn’t have a dependency on. Why is that considered “not a defect” of the current heuristics?

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSDoc typedef in a separate file - Stack Overflow
You can define types in a module (eg. typedefs.js ). The module contains your JSDoc typdefs and can simply export an unused property....
Read more >
Joshua's Docs - JSDoc Cheatsheet and Type Safety Tricks
Cheatsheet on using JSDoc, especially with VSCode, and some tips on type safety and advanced usage.
Read more >
declaration or statement expected.ts(1128) export - You.com
Expected behavior: MyClass.arg type should be available to be used in JSDoc in file-b.js . Generated declaration files should export all namespace's JSDoc...
Read more >
IntelliJ IDEA 2021.3 EAP (213.3714.8 build) Release Notes
Bug, IDEA-273910, IDE wrongly imports default pom.xml file if trying to add pom ... Run configuration getting module path wrong with indirect dependencies....
Read more >
tslint | Yarn - Package Manager
Change Log. v6.1.3. [bugfix] add support for TypeScript 4.0 peer dependency (#4943). v6.1.2. [ ...
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