import { IfNoDeepValue } from './helpers.js'; import { DeeperOmitReadonly, DeeperPickReadonly, DeepOmitReadonly, DeepPickReadonly, OmitReadonly, PickReadonly, } from './readonly.js'; import { IfNever } from './type-check.js'; /** * Make all properties in T mutable */ export type Mutable = { -readonly [K in keyof T as IfNever, never, K>]: T[K]; }; /** * Marks given keys as mutable */ export type MutableSome = Mutable> & Omit; /** * Make all properties in T mutable deeply */ export type DeepMutable = { -readonly [K in keyof T as IfNever< Exclude, never, K >]: IfNoDeepValue> extends true // Do not deep process No-Deep values ? T[K] : // Deep process objects DeepMutable>; }; /** * Make all properties in T mutable deeply */ export type DeeperMutable = { -readonly [K in keyof T as IfNever< Exclude, never, K >]: NonNullable extends (infer U)[] // Deep process arrays ? DeeperMutable[] : // Do not deep process No-Deep values IfNoDeepValue> extends true ? T[K] : // Deep process objects DeeperMutable>; }; /** * Returns mutable keys of an object */ export type MutableKeys = keyof OmitReadonly; /** * Pick all mutable properties in T */ export type PickMutable = OmitReadonly; /** * Omit all mutable properties in T */ export type OmitMutable = PickReadonly; /** * Pick all mutable properties in T deeply */ export type DeepPickMutable = DeepOmitReadonly; /** * Pick all mutable properties in T deeply */ export type DeepOmitMutable = DeepPickReadonly; /** * Pick all mutable properties in T deeply including arrays */ export type DeeperPickMutable = DeeperOmitReadonly; /** * Pick all mutable properties in T deeply including arrays */ export type DeeperOmitMutable = DeeperPickReadonly;