-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add JSDoc's @inheritDoc Support for Static Class Members for TypeScript #46719
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
Conversation
@@ -52,6 +52,6 @@ | |||
|
|||
verify.quickInfoAt("1", "constructor Bar(value: number): Bar", undefined); // constructors aren't actually inherited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone have ideas why constructors aren't actually inherited?
#23215 is kind of old, and it leaves a lot of questions underspecified.
Answering the inheritance questions seems like a lot of work. If I were writing this, I'd be very tempted to say that (1) the derived jsdoc must have |
src/services/services.ts
Outdated
if (declaration.modifiers?.some(modifier => modifier.kind === SyntaxKind.StaticKeyword)) { | ||
// For nodes like `class Foo extends Bar {}`, superTypeNode refers to an ExpressionWithTypeArguments with its expression being `Bar`. | ||
const baseClassSymbol = checker.getSymbolAtLocation(isExpressionWithTypeArguments(superTypeNode) && !superTypeNode.typeArguments?.length ? superTypeNode.expression : superTypeNode); | ||
const symbol = baseClassSymbol?.exports?.get(declaration.symbol.name as __String); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the usual way is getPropertiesOfType(getDeclaredTypeOfSymbol(s))
(though I'm not 100% sure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. It's actually getTypeOfSymbolAtLocation
because we are looking for static members of class.
////abstract class BaseClass { | ||
//// /** | ||
//// * Useful description always applicable | ||
//// * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test needs to show what happens when there's a param
tag for stuff
, and what happens when there's a param
tag for a parameter whose name is the same between base/derived.
//// } | ||
//// | ||
//// /** | ||
//// * @inheritDoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there's comment text on someProperty
? Is it discarded, appended, prepended, or is inheritdoc ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should be concatenated.
@Zzzen Do you want to keep working on this? Otherwise I'd like to close it to reduce the number of open PRs. |
Thanks for reminding me. And yes, I'm going to finish it. |
jsdoc.app says that it is provided for compatibility with Closure Compiler, which is written in java. Haven't check the source code of Closure Compiler, I think they should work like javadoc.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions, although it's quite possible that neither are fixable in this PR.
"text": "Applicable description always.", | ||
"kind": "text" | ||
}, | ||
{ | ||
"text": "\n", | ||
"kind": "lineBreak" | ||
}, | ||
{ | ||
"text": "text over tag", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought @inheritDoc
was supposed to insert the inherited text at the location of the tag. Here, it looks like it's getting prepended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like @inheritDoc
is dropping the subclass documentation in the new tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is OK as-is, but I don't want to merge until after 4.7 beta is over.
In the meantime, it's OK for
/**
* over
* @inheritDoc
* under
*/
To produce "Base\nover\under", but I still think it'd be better to produce "over\nBase\under".
const symbol = checker.getPropertyOfType(checker.getTypeAtLocation(superTypeNode), declaration.symbol.name); | ||
const baseType = checker.getTypeAtLocation(superTypeNode); | ||
const symbol = isStaticMember | ||
? find(checker.getExportsOfModule(baseType.symbol), s => s.escapedName === declaration.symbol.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getExportsOfModule
on the non-merged symbol of something that isn't a module? This doesn't seem right.
Fixes #23215