type Tail<T extends any[]> = ((...t: T) => void) extends ((
h: any,
...r: infer R
) => void)
? R
: never;
type DeepOmit<T, Path extends string[]> = T extends object
? {
0: Omit<T, Path[0]>;
1: {
[K in keyof T]: K extends Path[0] ? DeepOmit<T[K], Tail<Path>> : T[K];
};
}[Path['length'] extends 1 ? 0 : 1]
: T;
Run Code Online (Sandbox Code Playgroud)
我有上面的类型,效果很好。我已经这样测试过:
type A = DeepOmit<{ a: { b: { c: 1 } } }, ['a', 'b', 'c']>;
// { …Run Code Online (Sandbox Code Playgroud)