typelab / utils / ObjectReadonly
type ObjectReadonly<T, K> = IsObjectLiteral<T> extends true ? Detailed<{ readonly [Key in K]: T[K] } & { [Key in keyof T as Key extends K ? never : Key]: T[Key] }> : never;Extended TypeScript `Readonly` to enforce specific properties as readonly.
| Type Parameter | Description |
|---|---|
|
|
The original |
|
|
The keys of |
A type with the specified keys of T set as readonly.
type Obj = { a: string; b: string };
// { readonly a: string; b: string }
type ReadonlyObj = ObjectReadonly<Obj, 'a'>;