Skip to content

Return string completions for indexed access types #20941

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

mariusschulz
Copy link
Contributor

Fixes #20938

This PR provides string literal completions within indexed access types.

Does this look good to you, @DanielRosenwasser? Let me know if you need me to add anything else.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Looks good! Though I would also rename the test completionForStringLiteral14.ts to completionForStringLiteralInIndexedAccess01.ts

@@ -360,6 +369,18 @@ namespace ts.Completions {
return undefined;
}

function getStringLiteralCompletionsFromIndexedAccess(node: IndexedAccessTypeNode, typeChecker: TypeChecker, target: ScriptTarget, log: Log): CompletionInfo | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

Since this is mostly the same as getStringLiteralCompletionEntriesFromElementAccess, I would combine them into getStringLiteralCompletionEntriesFromElementAccessOrIndexedAccess, and call them with the appropriate type and stringLiteralNode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That definitely makes sense. Would you be okay with stringLiteralNode: Node as a parameter, or would you prefer stringLiteralNode: StringLiteral | NoSubstitutionTemplateLiteral?

@mariusschulz mariusschulz force-pushed the stringCompletionsForIndexedAccessTypes branch from 613f15d to 73d4461 Compare December 30, 2017 11:19
@mariusschulz
Copy link
Contributor Author

@DanielRosenwasser I've updated the PR based on your feedback. Instead of doing manual .kind comparisons, I'm now calling the type guard functions isStringLiteral(node) and isNoSubstitutionTemplateLiteral(node) so we can have TypeScript infer the type StringLiteral | NoSubstitutionTemplateLiteral for node. Does that work for you?

@mhegazy
Copy link
Contributor

mhegazy commented Jan 4, 2018

@mariusschulz can you please refresh the PR and address the merge conflicts

@mariusschulz mariusschulz force-pushed the stringCompletionsForIndexedAccessTypes branch from 73d4461 to be0c57d Compare January 5, 2018 17:11
@mariusschulz mariusschulz force-pushed the stringCompletionsForIndexedAccessTypes branch from be0c57d to 25c5e57 Compare January 5, 2018 17:14
@mariusschulz
Copy link
Contributor Author

@mhegazy Sure, done!

@DanielRosenwasser DanielRosenwasser merged commit 1041f09 into microsoft:master Jan 7, 2018
@DanielRosenwasser
Copy link
Member

Thanks Marius!

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
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