Declaration files built from JSDoc typedefs with optional parameters reference indirect dependency
See original GitHub issueBug 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:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.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?