Skip to content

Bad completions for string literal type as indexed access type object #40322

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

Closed
DanielRosenwasser opened this issue Aug 30, 2020 · 5 comments · Fixed by #40424
Closed

Bad completions for string literal type as indexed access type object #40322

DanielRosenwasser opened this issue Aug 30, 2020 · 5 comments · Fixed by #40424
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@DanielRosenwasser
Copy link
Member

Found while reading over #39697

let x: ""["bar"]

Request completions inside of "" and you'll get the names of every propery on String. What's happening is that we're not checking to see if the current string literal type is the argument type (as opposed to the object type itself).

Learning how this works might be a bit involved, but the fix is easy: add fourslash tests, add a single if check at

case SyntaxKind.IndexedAccessType:
// Get all apparent property names
// i.e. interface Foo {
// foo: string;
// bar: string;
// }
// let x: Foo["/*completion position*/"]
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode((parent.parent as IndexedAccessTypeNode).objectType));

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Good First Issue Well scoped, documented and has the green light Domain: Completion Lists The issue relates to showing completion lists in an editor labels Aug 30, 2020
@DanielRosenwasser DanielRosenwasser added this to the Backlog milestone Aug 30, 2020
@Vboivin
Copy link
Contributor

Vboivin commented Aug 31, 2020

@DanielRosenwasser I would like to take this issue as my first issue. Here are the fourslash tests I have currently: fourslashTests. Am I going in the right direction? Thank you

@DanielRosenwasser
Copy link
Member Author

I haven't used the array versions of marker, but if that test is currently failing on the first verify call, I think you're on the right track!

@denismaxim0v
Copy link

Has the issue been resolved?

@Vboivin
Copy link
Contributor

Vboivin commented Sep 6, 2020

Has the issue been resolved?

@denismaxim0v No, I am still on it

@DanielRosenwasser
Copy link
Member Author

Thanks @Vboivin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants