Incorrect inference/autocompletion on generic arrays, when values can be inferred from a defined object. #41645
Labels
Domain: Completion Lists
The issue relates to showing completion lists in an editor
Effort: Moderate
Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
Experience Enhancement
Noncontroversial enhancements
Experimentation Needed
Someone needs to try this out to see what happens
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
TypeScript Version: 4.1.2
Search Terms:
Autocompletion, incorrect, values, inference, generic, array, object, keys
Summary:
When an interface/a type has an object with generic keys, and an array of those keys, the array values cannot be infered from the object keys.
Code
Expected behavior:
Here, when trying to give a value to
allergens
, the autocompletion should show"eggs" | "flour"
.Actual behavior:
![image](https://user-images.githubusercontent.com/30944236/99950809-6bf03b80-2d7d-11eb-82c4-7636fda728a0.png)
The autocompletion doesn't find anything.
Notes:
The other way is working: you can fill the array first, then the object keys will autocomplete - but this rarely make sense to write things that way.
Failed workarounds:
This bug is still present, even when:
allergens
is optionnalkeyof this['quantities']
instead ofINGREDIENTS[]
The text was updated successfully, but these errors were encountered: