Skip to content
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

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

Open
DanielRosenwasser opened this issue Aug 30, 2020 · 4 comments
Open

Comments

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Aug 30, 2020

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

@Vboivin
Copy link
Contributor

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

@DanielRosenwasser DanielRosenwasser commented Aug 31, 2020

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

@denismaxim0v denismaxim0v commented Sep 6, 2020

Has the issue been resolved?

@Vboivin
Copy link
Contributor

@Vboivin Vboivin commented Sep 6, 2020

Has the issue been resolved?

@denismaxim0v No, I am still on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.