UNPKG

@flex-development/tutils

Version:
21 lines (20 loc) 776 B
/** * @file Type Definitions - DeepPick * @module tutils/types/DeepPick */ import type ObjectPlain from './object-plain.mjs'; import type OmitByType from './omit-by-type.mjs'; import type Path from './path.mjs'; import type PathValue from './path-value.mjs'; /** * Constructs a type by picking a set of properties `K` from `T`. * * @template T - Object type * @template P - Object path or paths union (dot notation friendly) */ declare type DeepPick<T extends ObjectPlain, P extends Path<T>> = OmitByType<{ [K in keyof T]: K extends P ? PathValue<T, K> : P extends `${infer Key}.${infer Rest}` ? K extends Key ? Rest extends Path<T[K]> ? { [K2 in Rest]: PathValue<T[K], Rest>; } : never : never : never; }, never>; export { type DeepPick as default };