-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Extending @typedefs by adding additional properties doesn't seem to work? #42877
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
Comments
@sami616 That's not a feature I'm aware of in jsdoc.app or closure, which are the two main systems that typescript tries to maintain compatibility with. I did a quick search for usage in the code bases we run tests on and could only find 5 uses total, in discord.js and cassandra-driver. To move forward with this feature, we'd need:
That's a lot of work, so my feeling is that this feature isn't worth it. |
@sandersn I wouldn't expect the feature to work as described in the OP. However, I would hope that something like this would work: /**
* @typedef {Object} ParentType
* @property {number} prop I want to keep my JSDocs
*/
/**
* @typedef {Object} ChildType
* @extends {ParentType}
* @property {string} field Here is the type information for the child
*/ This gives me an ergonomic way to extend the base type while maintaining any JSDocs associated with that type. If it's unfitting to use /**
* @typedef {Object} ParentType
* @property {number} prop I want to keep my JSDocs
*/
/**
* I get leaked
* @typedef {Object} BaseChildType
* @property {string} field Here is the type information for the child
*/
/** @typedef {ParentType & BaseChildType} ChildType */ This could be a source of confusion, and/or it could result in the over-suggestion of irrelevant types in IDEs. |
Responding to some of the earlier concerns: Evidence of lots of existing usageThis approach probably isn't being used right now because it doesn't work. But pretty much any existing codebase that defines an Why Not
|
I think you're better off specifying an Of course on that issue you'll need to discuss "Why not .d.ts files". Feel free to ping me on that; my quick opinion is that dividing |
Thanks for referencing that issue! I'll add some comments tomorrow -- Lord wiling. |
Added. |
I know this can be done with an intersection type, but that can often get quite verbose as it often requires an additional typedef to be defined.
As you can see in the below screenshot, i would expect
propThree
to be present in theextended
const.Is this syntax supported by vscode, looking around it seems to be in webstorm?
Sandbox example: https://codesandbox.io/s/vigilant-https-7h845?file=/src/Animal.js
The text was updated successfully, but these errors were encountered: