-
Notifications
You must be signed in to change notification settings - Fork 12.8k
const array to non readonly array cast compilation does not raise an error with [email protected] or [email protected] (like it does with [email protected] or [email protected]) #57107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm thinking this might be fallout from #55229 |
Fallout sounds like this wasn't intended there but, from what I can tell, this was a deliberate change introduced in this PR. While the PR's title might only mention type parameters and such - the change itself was broader, it affected cases like the one below and the team knew about it: const arr2 = [1, 2, 3] as const satisfies unknown[] // ok since that PR |
I wasn't sure since the stated purpose of the PR according to Anders was just to improve behavior for
He specifically calls out contextual typing via "a constraint that includes a mutable array type", not simply "a mutable array type" (the actual behavior clearly includes the latter). At no point in that PR could I find an acknowledgement of this behavior for non-generic contextual typing, but maybe I missed it... |
it has been mentioned in the design meeting notes that this change wasn't restricted to |
This is behaving as intended. I agree #55229 should have mentioned this applies to |
@ahejlsberg Well, you do mention |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
is:issue is:open const readonly array 5.3.3
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.3#code/MYewdgzgLgBAYgJQKoEkAqBlGBeGBtAKBhgCIBDABwoBsBTEgGiNICMyx2zHmSXqzgAaxa0ATqICe3YiWAALMZOmkQo9gHN6TGWogUR4qUwC6MMhBihIUANwECAegcwAIrQBmASzC0zMKBIUvgKgogAm3ur+IP4KMNCikWbiZBIEAUHwogCunlAWuAAUGbQg7vDI6BgAlHhg2QC2BsZ2jgBUbURtMBhyINnUYTAiMGEe3rRD5jAA5KK0ZGHg1BJZuVB4xjMwhQ2eEBBJ84vLq4K0EgDuqmHVAHRd-hDAMO5kntQWl3lyMACsdwAjHcAGwwVT-O4AJmhj3yLyWtAgYBmsDU+2ClhADQoHzIUE84Bgigh3ygvwBAGY7pTwaIYGBPOo5FAVjt8TA6OZYFAkbyhmSKXcACx3AAMAFoxgA3aFiqHCsWAqFi6pdBwEKzQGAIACiLgA+ohUJgAFxrPIQTY4fCyBSGRikXT6RRSUzTLW2exOGAAQQsesNxqqMH2DJAaIWSzAKwYMEuvmA7GJ0toYBgFGyEF+0rI1GySNDYCgMXJwRSq2Kcg5YdoAA8gsB+Y5nCXhr5jtG2dMEzAs5NYonwNrzlcbkXORMYABiQEADjVgaNlUwd0z2cK5CodBI1VaPoAColi4PkmpVlYoO9GWAomWzNvfABCTXDkB0O7UEDqQpL4OYPcCCAA
π» Code
π Actual behavior
With typescript 5.3.3 (or nightly, tested with 5.4.0-dev.20240120) the provided code compiles with no error.
π Expected behavior
The compilation with 5.3.3 (or with nightly, tested with 5.4.0-dev.20240120) should behave the same way as previous typescript releases (5.1.6, 5.2.2, ...) and raise a compilation problem at line 19 :
Additional information about the issue
In the playground simply switch typescript version (5.1.6, 5.2.2, 5.3.3, nightly) to see the compilation problem appear / disappear.
The text was updated successfully, but these errors were encountered: