Readonly Type


TypeScript comes with a Readonly type that makes all properties of a given type read-only.

type ReadonlyPoint = Readonly<Point>;

Exercise

Define a function that attempts to modify a ReadonlyPoint. Notice how TypeScript provides a compile-time error.


Copyright © learn-ts.org. Read our Terms of Use and Privacy Policy