TypeScript: Emulate ReadOnly built-in
13 August 2023 (Updated 13 August 2023)
type MyReadonly<Type> = {
readonly [Key in keyof Type]: Type[Key]
}
- Create a mapped type where you assign the
readonly
modifier to each property.
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment