Type alias DeepOmit<T, P>

DeepOmit<T, P>: P extends `${infer K}.${infer R}`
    ? {
        [KT in Keys<T>]: KT extends K
            ? DeepOmit<T[KT], R>
            : T[KT]
    }
    : Omit<T, P>

Type that recursively omits specified nested properties from an object type.

Type Parameters

  • T

    The input object type.

  • P extends string

    A string literal representing the path of properties to omit (e.g., 'person.name.value').

Example

type T =
a: {
b: string;
b2: {
c: {
d: number;
};
};
};
}

DeepOmit<T, 'a.b2.c'> // Results in: { a: { b: string; b2: {} } }