import { IfNoDeepValue } from './helpers.js'; import { DeeperOmitReadonly, DeeperPickReadonly, DeepOmitReadonly, DeepPickReadonly, OmitReadonly, PickReadonly, } from './readonly.js'; import { IfNever, IfTuple } 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, never, K> ]: IfNoDeepValue> extends true // Do not deep process No-Deep values ? T[K] : // Deep process objects (Exclude, not NonNullable - preserves a `| null` member) DeepMutable>; }; /** * Make all properties in T mutable deeply */ export type DeeperMutable = { -readonly [ K in keyof T as IfNever, never, K> ]: IfTuple> extends true // Deep process tuples positionally ? DeeperMutableTuple> : NonNullable extends readonly (infer U)[] // Deep process arrays ? // Always mutable - that is DeeperMutable's whole purpose null extends T[K] ? DeeperMutable[] | null : DeeperMutable[] : // Do not deep process No-Deep values IfNoDeepValue> extends true ? T[K] : // Deep process objects (Exclude, not NonNullable - preserves a `| null` member) DeeperMutable>; }; type DeeperMutableTuple = T extends readonly [infer Head, ...infer Rest] ? [ IfNoDeepValue> extends true ? Head : DeeperMutable>, ...DeeperMutableTuple, ] : []; /** * 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;