Infer array as tuple when used as rest argument in a complex expression #56765
Labels
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
"infer rest array type"
"infer rest array args"
"infer rest array tuple"
"spread argument array expression "
β Viability Checklist
β Suggestion
Given the following function
TypeScript already supports inferring that an array used as rest argument should be considered as a tuple:
But if you add some condition to the mix, type inference breaks:
My suggestion it to add support for inlined array inside complex expression to be used as spread args.
Playground link
π Motivating Example
I came accros this issue while designing a database agnostic module based on kysely.
I used to write stuff like so:
But this breaks the linear style of the definition. The following notation is more natural:
It currently work but requires additional typecasting (see playground link before)
π» Use Cases
The text was updated successfully, but these errors were encountered: