-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Support goto-definition for index signatures #23220
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
711cfc2
to
a716faa
Compare
src/services/goToDefinition.ts
Outdated
const type = checker.getTypeAtLocation(node.parent.expression); | ||
if (!type.getStringIndexType()) return undefined; | ||
const result: DefinitionInfo[] = []; | ||
for (const root of getRootSymbolsOfType(type, checker)) { |
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.
Can't you use getIndexInfoOfType
?
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.
👍 much better
@DanielRosenwasser Good to go? |
src/services/goToDefinition.ts
Outdated
const type = checker.getTypeAtLocation(node.parent.expression); | ||
return mapDefined(type.isUnionOrIntersection() ? type.types : [type], nonUnionType => { | ||
const info = checker.getIndexInfoOfType(nonUnionType, IndexKind.String); | ||
return info && createDefinitionFromSignatureDeclaration(checker, info.declaration); |
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.
info.declaration can be undefined, so you need to check that as well.
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.
Need test as well
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.
👍
Fixes #23212