3 ms·
> "where as readonly means it's only immutable when used from outside the class but still mutable inside the class" Small correction: The readonly modifier mea
by judah 10y ago
> "where as readonly means it's only immutable when used from outside the class but still mutable inside the class"
Small correction: The readonly modifier means you can initialize the variable, but can't mutate it (even within the same class). For example, you can initialize a readonly field inside a constructor, something you can't do with const.
Some good docs on it here: https://basarat.gitbooks.io/typescript/content/docs/types/readonly.html https://basarat.gitbooks.io/typescript/content/docs/types/re...
- jameslk 10y agoIt appears you're right: > Read-only properties may have initializers and may be assigned to in constructors within the same class declaration, but otherwise assignments to read-only properties are disallowed. Thanks for pointing that out.