-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Declaration files built from JSDoc typedefs with optional parameters reference indirect dependency #48242
Comments
Declaration emit has the following heuristics:
So you should be able to get the desired emit by writing /**
* @typedef PluginOptions
* @property {import('child').Options | undefined} [childOptions]
*/ Otherwise this is an expected property of the declaration emitter |
Why is |
Why is the originating declaration considered better than a re-export in this case? It seems inherently problematic to use the originating declaration if the originating declaration is importing it from another package. |
The originating declaration is considered better since it's more likely to have a meaningful name, is less likely to move around, requires fewer hops when navigating the code, etc.. Erasing an upstream dependency by re-exporting all of its symbols isn't a scenario for the declaration emitter (not that it would have that function here anyway). |
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 |
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? |
This is required for TypeScript to avoid referencing the wrong type (see microsoft/TypeScript#48242 (comment)).
Related-to: microsoft/TypeScript#48242. Closes GH-676.
This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
jsdoc
declaration files
optional parameters
.d.ts
grandchild
indirect dependency
π Version & Regression Information
β― 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
:parent/index.js
:π Actual behavior
parent/index.js
compiles to:This causes problem because
parent
doesn't have a direct dependency ongrandchild
π Expected behavior
parent/index.js
compiles to:Note that this works correctly if
childOptions
is not optional. As in, this:Correctly compiles to:
The text was updated successfully, but these errors were encountered: