Type alias DeepPick<T, P>

DeepPick<T, P>: UnionToIntersection<P extends P
    ? P extends `${infer K}.${infer R}`
        ? {
            [K1 in K]: DeepPick<T[K1], R>
        }
        : P extends Keys<T>
            ? Pick<T, P>
            : never
    : never>

Deeply pick properties from a nested object type.

Type Parameters

  • T extends Record<string, any>

    The target object.

  • P extends string

    A dot-separated string literal representing the path of properties to pick.

Example

type T = {
one: string;
two: {
a: boolean;
b: null;
c: 'c' | 'C';
};
thee: number;
};
DeepPick<T, 'two.c'> // Results in:
{
two: {
c: 'c' | 'C';
};
}