types-kit.setreadonly.md
September 4, 2023 ยท View on GitHub
Home > types-kit > SetReadonly
SetReadonly type
Make some properties in T readonly (add readonly decorator).
Signature:
export type SetReadonly<T, K extends Keys<T>> = Simplify<
StrictOmit<T, K> & Readonly<Pick<T, K>>
>
References: Keys, Simplify, StrictOmit
Example
interface Props {
a: number;
b: number;
c: number;
};
// Expect: { readonly a: number; readonly b: number; c: number; }
type NewProps = SetReadonly<Props, 'a' | 'b'>;