UNPKG

976 BTypeScriptView Raw
1import { Pick } from './Pick';
2import { Depth } from './_Internal';
3import { Key } from '../Any/Key';
4import { PatchFlat } from './Patch';
5import { Equals } from '../Any/Equals';
6/**
7 * @hidden
8 */
9export declare type OptionalFlat<O> = {
10 [K in keyof O]?: O[K];
11} & {};
12/**
13 * @hidden
14 */
15export declare type OptionalDeep<O> = {
16 [K in keyof O]?: OptionalDeep<O[K]>;
17};
18/**
19 * @hidden
20 */
21export declare type OptionalPart<O extends object, depth extends Depth> = {
22 'flat': OptionalFlat<O>;
23 'deep': OptionalDeep<O>;
24}[depth];
25/**
26 * Make some fields of `O` optional (deeply or not)
27 * @param O to make optional
28 * @param K (?=`Key`) to choose fields
29 * @param depth (?=`'flat'`) 'deep' to do it deeply
30 * @returns [[Object]]
31 * @example
32 * ```ts
33 * ```
34 */
35export declare type Optional<O extends object, K extends Key = Key, depth extends Depth = 'flat'> = {
36 1: OptionalPart<O, depth>;
37 0: PatchFlat<OptionalPart<Pick<O, K>, depth>, O>;
38}[Equals<Key, K>];