In this blog we can see using of readonly keyword in typescript .
Readonly in type script :
A feature of the language is the ability to instruct the Typescript compiler to make a property read-only.
Yes, that means that once it has been built, you cannot change its worth. A read-only property can only be set in the function Object() { [native code] } of a type script.
Although using the readonly keyword is a recommendation to avoid compile-time reassignment, there is no assurance that your code is secure and cannot be allocated to another location.
When using the readonly modifier, fields can be pre-fixed. Assigning to the field outside of the function Object() { [native code] } is prevented by this.
How then should readonly be used? when you don’t want to change a property’s value after it has been created.
Example :
class Product {
readonly name: string;
count: number;
constructor(name: string, price: number) {
this.name = name;
this.count = count;
}
}
For any Help or Queries Contact us on info@crmonce.com or +918096556344