Skip to content

Support goto-definition for index signatures#23220

Merged
3 commits merged into
masterfrom
goToDefinitionIndexSignature
Apr 9, 2018
Merged

Support goto-definition for index signatures#23220
3 commits merged into
masterfrom
goToDefinitionIndexSignature

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Apr 6, 2018

Fixes #23212

@ghost ghost requested review from armanio123 and sheetalkamat April 6, 2018 18:34
@ghost ghost force-pushed the goToDefinitionIndexSignature branch from 711cfc2 to a716faa Compare April 6, 2018 18:36
Comment thread 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)) {
Copy link
Copy Markdown
Member

@DanielRosenwasser DanielRosenwasser Apr 6, 2018

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍 much better

@ghost
Copy link
Copy Markdown
Author

ghost commented Apr 6, 2018

@DanielRosenwasser Good to go?

Comment thread 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);
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.

info.declaration can be undefined, so you need to check that as well.

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.

Need test as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍

@ghost ghost merged commit 998bead into master Apr 9, 2018
@ghost ghost deleted the goToDefinitionIndexSignature branch April 9, 2018 19:48
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants