You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The common pattern of literal array assignment with conditional inclusion of elements is one use case.
Code
type t = 'a'
// The common pattern
const a:t[] = [
...(true?['a']:[]),
]
// Minimal repro of phenomenon
const a:t[] = [
...['a']
]
The error messages given above are both Type 'string[]' is not assignable to type '"a"[]'.
Of course if the type of the nested array is asserted or otherwise known, the spread doesn't get in the way of that - it only seems to interrupt the automatic inference of the literal. We get as specific as string, but not as specific as the actual value.
Activity
DanielRosenwasser commentedon Dec 18, 2020
I think that issue is not quite related.
This seems pretty reasonable, though in the future please follow the template.
Playground Link
[-]No inference of array literal nested spread types[/-][+]Array spreads should be contextually typed[/+]mournie commentedon Dec 19, 2020
Yeah sorry - I used the "reference in new issue" button and it pre-filled the above quote instead of the standard template, so I just went with that.
mournie commentedon Dec 19, 2020
I guess object spread types are inferred in a way analogous to the way in which the array example isn't, so here's another example.
rentalhost commentedon May 24, 2023
Any updates on this case?
RyanCavanaugh commentedon Oct 20, 2025
Let's track at #45600
typescript-bot commentedon Oct 23, 2025
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.