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
Often people want to express in the type system that certain value is not to be modified by code accessing them. However, the Readonly<T> wrapper type does not work on Map and Set.
As a result, it's difficult to write a generic type that takes a mutable type argument and use a read-only version in the type body.
Examples
interfaceValidator<T>{isValid(x: SmartRO<T>);}
Checklist
My suggestion meets these guidelines:
[✔] This wouldn't be a breaking change in existing TypeScript / JavaScript code
[✔] This wouldn't change the runtime behavior of existing JavaScript code
[✔] This could be implemented without emitting different JS based on the types of the expressions
[✔] This isn't a runtime feature (e.g. new expression-level syntax)
The text was updated successfully, but these errors were encountered:
This was one of the proposals we discussed when adding conditional type support. The general consensuses was that we need a new readonly type operator (tracked by #10725). the type duplication for every entity causes other problems in inference, overload resolution, and in type comparisons.
I am going to say this is a duplicate of #10725, since #10725 fulfills the underlying scenario.
I should also add that you can always add this type in your project and use it as a wrapper for Readonly, but we do not have plans to add it to the standard library at the time being.
Search Terms
"readonly" type set
Suggestion
Add something like below to the standard library
Use Cases
Often people want to express in the type system that certain value is not to be modified by code accessing them. However, the
Readonly<T>
wrapper type does not work on Map and Set.As a result, it's difficult to write a generic type that takes a mutable type argument and use a read-only version in the type body.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: