import { IfNoDeepValue } from './helpers.js'; import { DeeperOmitRequired, DeeperPickRequired, DeepOmitRequired, DeepPickRequired, OmitRequired, PickRequired, } from './required.js'; import { IfNever, IfTuple } from './type-check.js'; /** * Marks given keys as optional */ export type PartialSome = Partial> & Omit; /** * Partial but deeply */ export type DeepPartial = { [K in keyof T as IfNever, never, K>]?: IfNoDeepValue< // Do not deep process No-Deep values Exclude > extends true ? T[K] : // Deep process objects (Exclude, not NonNullable - preserves a `| null` member) DeepPartial>; }; /** * Partial but deeply including arrays */ export type DeeperPartial = { [K in keyof T as IfNever, never, K>]?: IfTuple< NonNullable > extends true // Deep process tuples positionally ? DeeperPartialTuple> : NonNullable< // Deep process arrays T[K] > extends readonly (infer U)[] ? NonNullable extends any[] ? // was mutable - DeeperPartial doesn't touch mutability null extends T[K] ? DeeperPartial[] | null : DeeperPartial[] : null extends T[K] // was readonly - preserve that ? readonly DeeperPartial[] | null : readonly DeeperPartial[] : // Do not deep process No-Deep values IfNoDeepValue> extends true ? T[K] : // Deep process objects (Exclude, not NonNullable - preserves a `| null` member) DeeperPartial>; }; type DeeperPartialTuple = T extends readonly [infer Head, ...infer Rest] ? [ IfNoDeepValue> extends true ? Head : DeeperPartial>, ...DeeperPartialTuple, ] : []; /** * OptionalKeys * @desc Returns optional keys of an object */ export type OptionalKeys = keyof PickOptional; /** * Pick all optional properties in T */ export type PickOptional = OmitRequired; /** * Omit all optional properties in T */ export type OmitOptional = PickRequired; /** * Pick all optional properties in T deeply */ export type DeepPickOptional = DeepOmitRequired; /** * Omit all optional properties in T deeply */ export type DeepOmitOptional = DeepPickRequired; /** * Pick all optional properties in T deeply including arrays */ export type DeeperPickOptional = DeeperOmitRequired; /** * Omit all optional properties in T deeply including arrays */ export type DeeperOmitOptional = DeeperPickRequired;