Makes specified keys K readonly in each member of a union T.
K
T
This distributes over unions, ensuring each member is processed individually. Only keys that exist in each member are affected.
The target type (can be a union)
Keys to make readonly (defaults to all union keys)
type Result = MakeReadonly<{ a: string; b: number }>;// ^?// { readonly a: string; readonly b: number } Copy
type Result = MakeReadonly<{ a: string; b: number }>;// ^?// { readonly a: string; readonly b: number }
type Result = MakeReadonly<{ a: string } | { b: number }>;// ^?// { readonly a: string } | { readonly b: number } Copy
type Result = MakeReadonly<{ a: string } | { b: number }>;// ^?// { readonly a: string } | { readonly b: number }
type Result = MakeReadonly<{ a: string } | { b: number }, "a">;// ^?// { readonly a: string } | { b: number } Copy
type Result = MakeReadonly<{ a: string } | { b: number }, "a">;// ^?// { readonly a: string } | { b: number }
Makes specified keys
Kreadonly in each member of a unionT.This distributes over unions, ensuring each member is processed individually. Only keys that exist in each member are affected.