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
A property is allowed to have one of three states:
readonly
unknown
mutable
readonly properties are declared using readonly modifier, or as getters with no setters.
mutable properties are
readonly properties can not be assigned to if accessed directly. readonly properties are assignable to properties deemed "unknown", but not to mutable properties.
The rational here is ppl today do not have a way of expressing readonly, so existing typings do not really mean "mutable" by default. enforcing a default of mutability on these definitions will make using them with exiting typings much harder.
we still want to catch the most blatant violations of readonly, i.e. writing to a readonly property.
So:
interfaceI{x: number;}classC{getx(){return1;}}varc=newC();vari: I;c.x=1;// error, assigning to a readonly propertyi=c;// No error, c is assignable to i
Declaring ambient external modules
Related issues:
Problems:
Proposal:
Allow for short hand module declarations:
to be equivalent to:
Allow module names to have a wildcard character and match that in lookup
Additional the module "*" would allow for matching all unknown modules in the system, which can be used as a way to suppress all missing module errors
Report no-implicit-any errors for modules declared using the shorthand notaion
Open issue: is this reported on declaration or use sites
Readonly properties
Suggestion
PR
Design
A property is allowed to have one of three states:
readonly properties are declared using
readonly
modifier, or as getters with no setters.mutable properties are
readonly properties can not be assigned to if accessed directly. readonly properties are assignable to properties deemed "unknown", but not to mutable properties.
The rational here is ppl today do not have a way of expressing readonly, so existing typings do not really mean "mutable" by default. enforcing a default of mutability on these definitions will make using them with exiting typings much harder.
we still want to catch the most blatant violations of readonly, i.e. writing to a readonly property.
So:
Next steps
Merge Readonly properties and index signatures #6532
Add the mutable modifier
Look into a
readonly
type operator to generate a readonly version of a type e.g.The text was updated successfully, but these errors were encountered: