Skip to content

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

Merged
3 commits merged into from
Apr 9, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Apr 6, 2018

Fixes #23212

@ghost ghost requested review from sheetalkamat and armanio123 April 6, 2018 18:34
@ghost ghost force-pushed the goToDefinitionIndexSignature branch from 711cfc2 to a716faa Compare April 6, 2018 18:36
const type = checker.getTypeAtLocation(node.parent.expression);
if (!type.getStringIndexType()) return undefined;
const result: DefinitionInfo[] = [];
for (const root of getRootSymbolsOfType(type, checker)) {
Copy link
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
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
Author

ghost commented Apr 6, 2018

@DanielRosenwasser Good to go?

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
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
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
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