-
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
add enforceReadonlyAssignability
flag for smoother transition to true readonly modifiers
#13002
Comments
This was described at #6532 (comment) |
@Aleksey-Bykov |
@iashmeadows next time you are buying a car and you read "a sport BMW coupe", you say sweet, just what I wanted, you write a check, get your car and drive it home, next day you are all excited to show it to your friends, you stop at a store to get a 6 pack on the way there, you open the trunk and put your beer in it, when you close it you BMW turns into Honda Odyssey... you are like what? you are all pissed and stuff, you take the beer out and it turns into BMW again, you are like what!!! you call the dealer who sold it to you, they drop on you first, it's normal, then they pick up and say you know it's accoring to issue #6532 where some housewife complained that the trunk of BMW isn't big enough for shopping at Costco and taking kids to the beach, and that's exactly why we made a hard decision to turn iT into Honda Odyssey every time anything is put in its trunk, you are like wtf!!! So you go there and you are like: nothing was said about this shit anywhere! And what you hear back is: well we never said we sell true BMW''s why are you surprised? And people around who saw it are like: hey let's be adults here. F**k what? |
Regardless of whether or not I agree on that perspective of |
@Aleksey-Bykov In case you missed it, the "we're all consenting adults here" was a reference to a common saying in the Python ecosystem, regarding member privacy, types, etc. 😉 (Basically, conventions are usually sufficient to imply "you're on your own" for diving into internals, and there's only so much you can do to prevent them from doing it, especially without the use of closures.) |
@isiahmeadows
Python gets a lot of things wrong. I never understood the appeal and popularity of that language. Irregardless that doesn't make it a good basis for anything.
I don't see the relevance, Regardless, Scala has a nominal type system with support for optional explicit structural subtyping. Furthermore it doesn't permit these types of readonly violations. I don't think it is the right analogy. I'm not saying TypeScript made a bad decision here, but personally I think it would have been great if |
Type driven emit would be nice in many scenarios, but even if we never get that, a type error here would be useful. Do |
Re: comments above, the issue here is not to do with emit, or the fact that readonly doesn't mean const. It's just the looseness of type checking between the interfaces with mismatched properties. If a property could be explicitly marked |
here is a dichotomy: a property is either readonly or writable, there is no other outcome when we say what else do we need? what is the third state implied by |
That would be the ideal if the
So now we have a trichotomy:
If interface WritableData {
mutable value: number;
} would no longer be compatible with I think of this as similar to the bivariance compromise in TS today. Any fix to it in the future will allow us to improve the situation where we ask for it, but the default will have to continue to be bivariance, to avoid breaking so much existing user code. (OTOH as TS 2.0 was a major version bump, maybe a massive breaking change would be acceptable to some, but TS is more cautious than that, which is a good thing IMO). |
@Aleksey-Bykov Indeed a @danielearwicker specifically for that reason there should not be new syntax because the old syntax will have to mean what the new syntax means implicitly and indefinitely. All this will do is create cognitive load |
It could be behind a flag : usually it's a convenient way to handle these kind of breaking changes. |
But that isn't what the old syntax meant. All widely used languages are products of evolution and contain some scars of that process. Only academic niche languages that no one uses are totally spotless. Look at it this way: suppose functional programming takes over the world and everyone's properties are all now |
@abenhamdine - yes though I expect there would be implications for maintaining type definition files so they can be used either way. If we have So even then, we'd still need |
It depends on how you look at it. TypeScript already changed the meaning of a lot of code by introducing the function f() {}
f.name = 'g'; which has no effect under sloppy mode and throws in strict mode. Either way the code was wrong but there was no way to model that. This also implies the prevailing assumption was mutability which makes perfect sense given the nature of JavaScript. |
no, this is exactly what it meant as far as expressive power of TS at that time, everything used to be modeled with mutable properties (even things that were not supposed to be mutable by design)
exactly, leave the old code alone, readonly is an opt-in thing, if you want it only then you use it how can it break anything if it's not in your code? there is no single reason for delivering this feature halfbaked and use "breaking change" as an excuse whoever stuck in 3 years behind:
but regardless of how you go about delivering a new "opt-in" feature, it's not an excuse to cut it short in favor of easier transition |
But that's a great use of a breaking change - to turn a runtime error into a compile time error. Like you say, the code was wrong, and now that can be statically discovered. |
Because it's in type definitions your code uses. @RyanCavanaugh - It seems not. |
@Aleksey-Bykov I believe this is because |
you cracked me up :) so when you see |
let me share a secret:
problem solved |
Cool, issue closed then! |
@RyanCavanaugh I suppose not. An off by default, option in the vein of |
enforceReadonlyAssignability
flag for smoother transition to true readonly modifiers
in support of the previous speaker, the topic was renamed |
Tracking this at #13347 |
To be honest I miss the old title. It was so much more memorable. These days, when I get frustrated with |
this can be seen in the nightly build as of Dec 17 (as well as at playground)this can't be serious, can it?why is it called readonly?please note there are no type assertions or any other attempts to trick the type system, it just simply doesn't work50+ errors left uncaughtUPDATE
constructive discussion starts here: #13002 (comment)
The text was updated successfully, but these errors were encountered: