Is ReadonlySet
means set of ReadOnly
properties as same as ReadOnlyCollection in C#?
I am not able to find out any document for it from anywhere. Could you please let me know what is the use of ReadonlySet
and How can we do implementation of it?
let readonly: Readonly<number> = 1;
let readonlySet: ReadonlySet<number> = ???//
ReadonlySet
is a type similar to Set
, but it does not have a add
/ delete
method, so elements can only be added during construction:
const regular: Set<number> = new Set([1,2,3]);
regular.add(4);
const readonly: ReadonlySet<number> = new Set([1,2,3]);
readonly.add(4) //fails, add not a function
Reference
Unlike the readonlySet in C# you referenced, typescripts ReadonlySet is not actually a class/constructor. Its just a type. As typescript has duck typing, the Set
is kind of a superclass to ReadonlySet
, so the type can be "typecasted". This is actually only for typechecking, it has no runtime influence.At runtime, it's just a JavaScript Set
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With