-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
2.4: Readonly<Map<k,v>> vs. ReadonlyMap<k,v> #16840
Comments
You cannot make a Map read only with Object.freeze. Sounds like this is working as intended to me. |
That's surprising. @sylvanaar can you provide a reference supporting this? No matter what the runtime-behavior, Its is a change in compile-time behavior from TypeScript 2.3.x., |
https://stackoverflow.com/questions/35747325/is-there-a-way-to-freeze-a-es6-map Also, you can test it yourself: http://jsbin.com/zorumaceyu/edit?js,console I think they gave a reasonable type for a Map returned from Object.freeze in the current release Readonly<Map> #12377 they added support for ReadOnlyArray, buit shouldn't have. |
We need new overloads to freeze,: freeze<K,V>(a: Map<K,V>): ReadonlyMap<K,V>; and set as well since we are at it: freeze<T>(a: Set<T>): ReadonlySet<T>; |
PRs welcomed |
@mhegazy , as @sylvanaar 's comment/link shows, calling Object.freeze on a map doesn't actually stop new keys being added with .set(). Do the suggested overloads still make sense in this case? |
|
Interestingly |
TypeScript Version: 2.4.1
Code
Expected behavior:
Compiles without error in tsc@<2.4.0
Actual behavior:
The text was updated successfully, but these errors were encountered: