-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Readonly<[...unknown[], infer L]>
and readonly [...unknown[], infer L]
exhibit inconsistent behavior.
#56888
Comments
Nice find. I find it hard to believe that some problems like this were not already reported but I can't find any issues related to this. The problem can be shown in a much simpler example that doesn't involve any infer type parameters: type Result = Readonly<[...string[], number]>
// ^? type Result = readonly [...(string | number)[], string | number] Since |
That homomorphic behavior makes me think this is related to #56885 |
The underlying mechanism that is responsible for both is currently the same. I think I've read some comments very recently about this other case being the limitation of the current design - it could potentially be improved but it's a known behavior of the current design and it's considered to be the correct behavior per the current implementation. The issue here feels different because the user doesn't interact explicitly with property access like this - it's just coincidental that when the mapping is done internally it goes through |
I re-read the @craigphicksβs comment there and there is definitely something off there. I distinctly remember reading a comment about this behavior with variadic+trailing required elements to be by design today but i might be misremembering what iβve read or maybe it was an outdated comment or smth |
Not to derail things too much, but...
The relevant comment was recently linked by @jcalz and is from Anders's original PR that implemented leading/middle rest elements: #41544
I can't find anything that suggests this behavior has (or should have) changed. Craig points to #49138 being fixed in 5.0.4 but that issue is about assignability, not indexing. |
The fix there was introducing bi-directional matching - from both end towards the middle.
#56885 started out as a bug report #56883, but that was closed and reopened as a feature request. Currently it doesn't look like a feature request, and I have recommended to @13OnTheCode that it be rewritten as a proper feature request. Hopefully that same indexing feature improvement would eventually be reflected here as well. |
Simpler repro: type R1<T> = readonly [...unknown[], T]; // readonly [...unknown[], T]
type R2<T> = Readonly<[...unknown[], T]>; // readonly [...unknown[], unknown] |
π Search Terms
Readonly<[...unknown[], infer L]>
andreadonly [...unknown[], infer L]
exhibit inconsistent behavior.π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.2#code/C4TwDgpgBAglC8UBKECGATA9gOwDYgB4BtAOjIFdsBrbTAd2yIF0AaKSm+7JgPgFgAUFCgB6EVAB6AfkGDQkKACEEUAE5oseEFFIVqtBszYcD3QcLGSZAueGgAVAIwqiAclSu2rgEaeorgGNXJigIAA9gCGx0AGc1DRx8HQBLbAAzCFUoAAk2MhITLmYQqRyoAC4obAgAN0zzUXFpWQF5BwAmF3c-Hx6gkPDI6LiUDETCIlSMrNyofMLDJl4oUuyKqtr6oUarFraoewBmLo8vXy9+0Iio2PixrR15-SLWKCnMqAAZEq-16rrVA1LM0bK07AcACwnHrnfyXQY3EYJLTEJ6cRZsd5Zb48Fa-Sr-LYWJrWYmwALAcioXCVBbYIHiACiYUgFIg6EqgVcgiAA
π» Code
π Actual behavior
π Expected behavior
Infer the correct type.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: