Readonly type under the hood in TypeScript
6 Apr 2021
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:
Make values readonly
To make first layer of properties immutable, we use readonly modifier and that's it ✅
Check out the solution in Playground ⭐️
typescript