-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Overriding methods has no way to inherit the parameter documentation from the superclass #24259
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
|
This is similar to #31267 I think. It has a PR but seems to have been abandoned. |
|
As far as I can see this is resolved at least since v4.2.3: class CoolClass {
/**
* I'm some neat and cool JSDoc info about `method`!
* @param arg I'm some information about an argument
*/
method (arg: any) {}
}
class NotAsCoolClass extends CoolClass {
method (arg: any) {}
}
const x = new NotAsCoolClass();
x.method // also has parameter documentation |
So you'd like to be able to override methods and not add types to parameters because the types could be inherited from the parent class? Interesting point. The information is redundant, therefore it could be done. On the other hand: If I change a type in a parent class, errors would pop up not in the signature (incompatible signatures) but in the implementation. This would make it much harder to actually find the reason for the problem. BUT: This is not the topic of this Issue. IMO this one can be closed. |
|
As stated above, this was actually resolved at some point without this issue being closed. |
|
For me it still doesn't show up in VSCode, found a solution though: class Parent {
/**
* @param {string} a ...
* @param {number} b ...
*/
method(a, b) {
// ...
}
}
class Child extends Parent {
/** @inheritdoc @type {Parent['method']} */
method(a, b) {
super.method(a, b);
// ... do extra stuff ...
}
}Which will help VScode infer the types. |
|
It seems it still does not work properly in VSCode with TypeScript 5.5.
#31267 was closed last week without any explanation. I am planning to open a new issue -- any thoughts? |


Uh oh!
There was an error while loading. Please reload this page.
Search Terms
override param parameters doc documentation function method extends
The Problem
In this code example,
methodgets the following documentation:It does not get
@paramdocumentation (or any other@documentation parameters). However, this would be very, very helpful to have. The main use case I have for it is for a modding API for my project. The way we currently handle it is we have an interface containing all our "hook" methods, and then a "Mod" class that implements that interface. All the hook methods on it are called by our code internally.A modder can extend the Mod class to hook into the base code. The works great for us, however, this means that the documentation we have on the hook methods is only the method description and nothing about the parameters of the hooks (which is pertinent information).
Suggestion
Keep the
@paraminformation on methods without other documentationI assume the main reason the information isn't currently kept is because subclass methods can do different things with the parameters. However, throwing them out all the time is a bit of an extreme solution. I suggest that if the subclass doesn't provide it's own documentation, it should keep all documentation from the superclass method. I think that 100% of the time it would be more useful for it to work this way.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: