import { IfNoDeepValue } from './helpers.js'; import { Or } from './logical.js'; import { IfFunction, IfNever, IfTuple } from './type-check.js'; /** * Construct a type with the properties of T except for those in type K, * while preserving strict type checking. */ export type StrictOmit = { [K in keyof T as K extends X ? never : K]: T[K]; }; /** * Omit all function properties in T */ export type OmitFunctions = { [ K in keyof T as Or< // Omit never keys IfNever>, // Omit functions IfFunction> > extends true ? never : K ]: T[K]; }; /** * Exclude from properties of T those types that are assignable to X */ export type OmitTypes = { [K in keyof T as IfNever, never, K>]: Exclude< T[K], X >; }; /** * Omit all function properties in T */ export type DeepOmitTypes = { [ K in keyof T as IfNever, never, K> ]: IfNoDeepValue> extends true // Do not deep process No-Deep values ? Exclude : // Deep process objects (Exclude, not NonNullable - preserves a `| null` member) DeepOmitTypes, X>; }; /** * Omit all function properties in T deeply including arrays */ export type DeeperOmitTypes = { [K in keyof T as IfNever, never, K>]: IfTuple< NonNullable > extends true // Deep process tuples positionally ? DeeperOmitTypesTuple, X> : NonNullable< // Deep process arrays // Do not deep process No-Deep values T[K] > extends readonly (infer U)[] ? NonNullable extends any[] ? // was mutable - DeeperOmitTypes doesn't touch mutability null extends T[K] ? DeeperOmitTypes[] | null : DeeperOmitTypes[] : null extends T[K] // was readonly - preserve that ? readonly DeeperOmitTypes[] | null : readonly DeeperOmitTypes[] : IfNoDeepValue> extends true ? Exclude : // Deep process objects (Exclude, not NonNullable - preserves a `| null` member) DeeperOmitTypes, X>; }; type DeeperOmitTypesTuple = T extends readonly [infer Head, ...infer Rest] ? [ IfNoDeepValue> extends true ? Exclude : DeeperOmitTypes, X>, ...DeeperOmitTypesTuple, ] : [];