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

Code hint not narrowed properly on union of literal tuple #46457

Open
k8w opened this issue Oct 21, 2021 · 4 comments Β· May be fixed by #58571
Open

Code hint not narrowed properly on union of literal tuple #46457

k8w opened this issue Oct 21, 2021 · 4 comments Β· May be fixed by #58571
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Help Wanted You can do this
Milestone

Comments

@k8w
Copy link

k8w commented Oct 21, 2021

Bug Report

πŸ”Ž Search Terms

  • code hint tuple
  • code hint union

πŸ•— Version & Regression Information

4.4.4

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

let value: ['a', 'v1'] | ['b', 'v2'] = ['a', 'v']; // Type 'v' here and get code hint

πŸ™ Actual behavior

image

The first element is 'a', so the type of value should be narrowed to ['a', 'v1'].
So that the code hint of the second element should only have 'v1', but actually got 'v1' | 'v2'.

The compile result is correct, but it is not consistent with code hint.

πŸ™‚ Expected behavior

image

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Help Wanted You can do this labels Nov 4, 2021
@DanielRosenwasser DanielRosenwasser added this to the Backlog milestone Nov 4, 2021
@DanielRosenwasser
Copy link
Member

We probably ask for smarter completions in object literals based on discriminants, but not in tuples. Seems like we could and should do the same here.

@RyanAfrish7
Copy link

@DanielRosenwasser, can I pick this up?

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Nov 29, 2021

I wouldn't recommend working on this issue unless you've already tackled other smaller issues (which are marked good first issue).

@johnsonjo4531
Copy link

Not sure if motivating examples are welcome here, but this would be a really great feature to get autocomplete on the second .get() example here. The first is already possible through template literal types.

var object = { 'a': [{ 'b': { 'c': 3 } }] };
 
_.get(object, 'a[0].b.c');
// => 3
 
_.get(object, ['a', '0', 'b', 'c']);
// => 3

https://lodash.com/docs/4.17.15#get

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 Effort: Casual Good issue if you're already used to contributing to the codebase. Harder than "good first issue". Help Wanted You can do this
Projects
None yet
4 participants