Skip to content

Jsdoc property description - #50269

Merged
Wesley Wigham (weswigham) merged 16 commits into
microsoft:mainfrom
danay1999:jsdocPropertyDescription
Aug 25, 2022
Merged

Jsdoc property description#50269
Wesley Wigham (weswigham) merged 16 commits into
microsoft:mainfrom
danay1999:jsdocPropertyDescription

Conversation

@danay1999

Copy link
Copy Markdown
Contributor

Fixes #47933

Comment thread src/compiler/checker.ts Outdated
const expressionType = checkExpressionCached(name.expression);
const infos = getApplicableIndexInfos(expressionType, getLiteralTypeFromPropertyName(name.name));
if (length(infos) && infos[0].declaration && infos[0].declaration?.symbol.flags & SymbolFlags.Signature && infos[0].declaration?.jsDoc) {
const copy = createSymbol(SymbolFlags.Signature, InternalSymbolName.Index);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we creating a new symbol here? Given

interface Foo { [key: string]: any }
declare let foo: Foo;
foo.bar;
foo.bar;
foo.bar;
foo.bar;

every mention of foo.bar would have its own copy of the index symbol, which seems wrong.

@weswigham Wesley Wigham (weswigham) Aug 18, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested it to handle filtering the symbol's declarations to only those matching the use site in order to handle when multiple index signatures exist (since all index signatures usually get tossed into the same __index symbol, rather than each having their own). Certainly, if the filtered list of applicable index signature declarations is identical to the full list, reusing the original symbol should be OK, and we could probably cache and reuse symbols when they're the same declaration subset across usages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New approach, as explained by Wesley Wigham (@weswigham)

  1. If infos is the same as all the infos available in the type, just return the InternalSymbolName.Index member of the type directly.
  2. If you do have to make a filtered one - cache it for each set of declarations you use. Add a member to SymbolLinks and store the cache on the original Index symbol, keyed by the list of (ids of) declarations in the filtered symbol.

Comment thread src/services/symbolDisplay.ts Outdated
Comment thread src/services/symbolDisplay.ts Outdated
Comment thread src/services/symbolDisplay.ts Outdated
Comment thread src/services/symbolDisplay.ts Outdated
Comment thread src/services/symbolDisplay.ts Outdated
Comment thread src/services/symbolDisplay.ts Outdated
Comment thread src/services/symbolDisplay.ts Outdated
if (flags & SymbolFlags.SetAccessor) return ScriptElementKind.memberSetAccessorElement;
if (flags & SymbolFlags.Method) return ScriptElementKind.memberFunctionElement;
if (flags & SymbolFlags.Constructor) return ScriptElementKind.constructorImplementationElement;
if (flags & SymbolFlags.Signature) return ScriptElementKind.indexSignatureElement;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SymbolFlags.Signature is also used for call and construct signatures. If tests are passing this might be fine, but I would want to understand why you don’t have to worry about call and construct signatures here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not sure about this. The function returns ScriptElementKind.memberVariableElement ('property') for SymbolFlags.Property which is the other example I was looking at, I want to return ScriptElementKind.indexSignatureElement ('index') for SymbolFlags.Signature which is why I added this here, but I wasn't aware of SymbolFlags.Signature also being used for call and construct signatures.

Comment thread src/compiler/checker.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking much better, almost there 👍

Comment thread src/compiler/checker.ts Outdated
Comment thread tests/cases/fourslash/jsDocPropertyDescription10.ts
@weswigham
Wesley Wigham (weswigham) merged commit a08b045 into microsoft:main Aug 25, 2022
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

jsdoc property description does not work on index signatures

5 participants