Immutable Data with Readonly
This lesson explains the 'readonly' mapped type.
We'll cover the following
The Object.freeze
function
One well-known JavaScript function that has a mapped type already backed in TypeScript is the Object.freeze
. The role of this function is to take a type and return everything as read-only. The function will have a return type of Readonly<T>
where T
is the interface to freeze. The name ‘mapped’ comes from the fact that within the type, there is an instruction with the keyword in
which will loop through all the object properties and prototype chains.
Get hands-on with 1200+ tech skills courses.