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
const type parameters don't work with mutable array constraints #51931
Oh, that... it is somewhat unexpected at the first glance but in retrospect, I understand this reasoning. But in such a case - const modifier with a mutable array constraint doesn't make sense. Could we add a diagnostic about this?
Those two are also interesting but I don't have a clear understanding of what a spread does to a type parameter, so maybe both here are exped. Could you take a look?
Should the second one benefit from const? The readonly modifier seems to be always lost when spreading (existing behavior predating const) and that's probably why the first one doesn't "fallback" to the constraint type but perhaps the inferred elements for the second one should be narrowed down here?
changed the title [-]`const` doesn't work mutable array constraints[/-][+]`const` type parameters don't work with mutable array constraints[/+]on Aug 25, 2023
Activity
MartinJohns commentedon Dec 17, 2022
Just pointing out that
readonly any[]does work.ahejlsberg commentedon Dec 17, 2022
This is working as intended. See the last part of the description here for the rationale.
Andarist commentedon Dec 17, 2022
Oh, that... it is somewhat unexpected at the first glance but in retrospect, I understand this reasoning. But in such a case -
constmodifier with a mutable array constraint doesn't make sense. Could we add a diagnostic about this?Those two are also interesting but I don't have a clear understanding of what a spread does to a type parameter, so maybe both here are exped. Could you take a look?
Should the second one benefit from
const? Thereadonlymodifier seems to be always lost when spreading (existing behavior predatingconst) and that's probably why the first one doesn't "fallback" to the constraint type but perhaps the inferred elements for the second one should be narrowed down here?typescript-bot commentedon Dec 20, 2022
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
[-]`const` doesn't work with `extends`[/-][+]`const` doesn't work mutable array constraints[/+][-]`const` doesn't work mutable array constraints[/-][+]`const` type parameters don't work with mutable array constraints[/+]