Readonly
Problem - On Github
The aim is to build the inbuilt Readonly
utility type.
Out initial type given by the puzzle creator is
type MyReadonly<T> = any
Solution
If we think about what needs to happen this time is we take all the keys of a given object, and make those keys readonly.
So our type should:
- be an object -
{ ... }
- have its keys be read only -
{ readonly [... ] ...}
- and have the keys and values from the
T
object -[Key in keyof T]
So the answer is:
type MyReadonly<T> = {
readonly [Key in keyof T]: T[Key]
}
What to read more? Check out more posts below!