import type {IsEqual} from './is-equal'; import type {ConditionalExcept} from './conditional-except'; import type {ConditionalSimplifyDeep} from './conditional-simplify'; import type {UnknownRecord} from './unknown-record'; import type {EmptyObject} from './empty-object'; import type {IsPlainObject} from './internal'; /** Used to mark properties that should be excluded. */ declare const conditionalPickDeepSymbol: unique symbol; /** Assert the condition according to the {@link ConditionalPickDeepOptions.condition|condition} option. */ type AssertCondition = Options['condition'] extends 'equality' ? IsEqual : Type extends Condition ? true : false; /** ConditionalPickDeep options. @see ConditionalPickDeep */ export type ConditionalPickDeepOptions = { /** The condition assertion mode. @default 'extends' */ condition?: 'extends' | 'equality'; }; /** Pick keys recursively from the shape that matches the given condition. @see ConditionalPick @example ``` import type {ConditionalPickDeep} from 'type-fest'; interface Example { a: string; b: string | boolean; c: { d: string; e: { f?: string; g?: boolean; h: string | boolean; i: boolean | bigint; }; j: boolean; }; } type StringPick = ConditionalPickDeep; //=> {a: string; c: {d: string}} type StringPickOptional = ConditionalPickDeep; //=> {a: string; c: {d: string; e: {f?: string}}} type StringPickOptionalOnly = ConditionalPickDeep; //=> {c: {e: {f?: string}}} type BooleanPick = ConditionalPickDeep; //=> {c: {e: {g?: boolean}; j: boolean}} type NumberPick = ConditionalPickDeep; //=> {} type StringOrBooleanPick = ConditionalPickDeep; //=> { // a: string; // b: string | boolean; // c: { // d: string; // e: { // h: string | boolean // }; // j: boolean; // }; // } type StringOrBooleanPickOnly = ConditionalPickDeep; //=> {b: string | boolean; c: {e: {h: string | boolean}}} ``` @category Object */ export type ConditionalPickDeep< Type, Condition, Options extends ConditionalPickDeepOptions = {}, > = ConditionalSimplifyDeep extends true ? Type[Key] : IsPlainObject extends true ? ConditionalPickDeep : typeof conditionalPickDeepSymbol; }, (typeof conditionalPickDeepSymbol | undefined) | EmptyObject>, never, UnknownRecord>;