Autocomplete breaks after one property for an array generic #57879
Labels
Domain: Completion Lists
The issue relates to showing completion lists in an editor
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
π Search Terms
array generic
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.2#code/C4TwDgpgBAsg9gEwgGwMLIIYFcDOEA8AKgHxQC8UA3gFBR1QDyASgPwBcsiK62eRxAbQC6Ablr0AggDkAIu05I0mXARLCxAXygAyKAAUMAJ2ABLDMn5jqoSFABCGPAEUsEQyCJQIAD2AQAdgg4UDjAhib+AOYANFAAql6+AUFQcABGAFYQAMbApBQ09FAAtlzIHIRiRQCOru7y8Io8KvhxxJpWNtBxeIYubiDk9o4Q-e74AEQ9bhOxlFD+GMUQHKHhUSJQGJErC1jFaW5QGu3W4NB6cKE4Y4MUDs51HhOX17NUUKbAyLtrEZGbbJwfx+EGrML-Y6nM62W5DaZ9J5QAA++iuwBuTysADMsP5ciZgZ8IKF-p4fKCUrdiAAKWoDCrCACUVHEdCB-hwcB+ADpkHBInSnkzNNRqLj8aYiX5SVEAEzkpKBYK3YS0+nuCoswr0Dlc3n8wUakAi6gaMUy0xRGkCNmsopFUqKDhTXqzO01J4cHUOh2LZYuy3u32+gD0oaghHAkO20AAFm5oAB3EzIZBbLDAOBA4pgH5+D0h2McACMAAZC3QNNE7dXqEJTdYSVbInKbXafQ6nSgXQjgyHjd7K36lrsJkGayGHeHI+5PtGolsdlAE4YILETMAoEngQByLfYLM5vMQAtTutFOsNsRAA
π» Code
π Actual behavior
For the
testing
function, you correctly get suggested fields when filling in thequery
property.However, for
testing2
, the suggestion works for your first property, whichever one you try.However, once the first one is provided, it will stop autocompleting.
Once one has been provided, you can also list any key, regardless of if it's part of the model.
π Expected behavior
It should correctly suggest all properties and typecheck additional properties and not stop working after the first one.
Additional information about the issue
Some extra context why I'm using the
testing2
approach, here's a playground link that shows what I'm trying to achieve.Basically, I want to make sure that the return value of my function adheres to what was passed in. I haven't found a way to do it with
testing
, so I went fortesting2
, which is a decrease in DX since it'll only autocomplete one query parameter.But the return value is exactly what I want
(for reference for others who would stumble upon this issue, the last
as const
is important to ensure it returns the correct order, else it will have a type ofconst returnValue: (UserModel | PostModel)[]
)The text was updated successfully, but these errors were encountered: