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
{{ message }}
Repository navigation
Literals that are spread into a const rest are not const-ified #53177
When spreading an array expression its elements are not acting like they are in the const context. When spreading a string it's not even inferred as a tuple of strings.
🙂 Expected behavior
I'm not exactly sure what is the expected result here - I can see the argument going both ways. I just think that perhaps this is a little bit underspecified today and that this issue, at the very least, might help to specify the desired behavior for those cases.
This is working as intended. Spread elements intentionally don't have contextual types, so the const-ness isn't propagated to the tuple type. It would add a good deal of complexity to compute contextual types for spread expressions, and in many cases it just isn't possible. Furthermore, in real world code, spread expressions are pretty much never literals as that's just a more inconvenient way of writing the elements directly inline.
Activity
RyanCavanaugh commentedon Mar 9, 2023
Anders Hejlsberg (@ahejlsberg) thoughts?
ahejlsberg commentedon Mar 9, 2023
This is working as intended. Spread elements intentionally don't have contextual types, so the const-ness isn't propagated to the tuple type. It would add a good deal of complexity to compute contextual types for spread expressions, and in many cases it just isn't possible. Furthermore, in real world code, spread expressions are pretty much never literals as that's just a more inconvenient way of writing the elements directly inline.
Andarist commentedon Mar 9, 2023
Thanks for the answer! It’s pretty much what i expected but was a little but unsure about.