beraliv

Readonly type under the hood in TypeScript

Example of Readonly use
Example of Readonly use

Second challenge is Readonly

Similarly to Pick, it's usually used when you need to declare the type which is based on another type. The values on the first layer are immutable, or readonly 🔒

Iteration over an object

As previously for Pick, we use Mapped Types for the iteration:

Example of Mapped Types
Example of Mapped Types

Make values readonly

To make first layer of properties immutable, we use readonly modifier and that's it ✅

Solution
Solution

Check out the solution in Playground ⭐️

typescript
Alexey Berezin profile image

Written by Alexey Berezin who loves London 🏴󠁧󠁢󠁥󠁮󠁧󠁿, players ⏯ and TypeScript 🦺 Follow me on Twitter