typelab / utils / ObjectOmitRequired
type ObjectOmitRequired<T, Z> = IsObjectLiteral<T> extends true ? { [K in keyof T as IsOptionalProperty<T, K> extends true ? K : never]?: _Lookup<Z, { shallow: T[K]; deep: ObjectOmitRequired<ExcludeUndefined<T[K]>> }> } : T;Get the optional properties from T type.
This type will lookup all nested objects (if Z is 'deep').
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The |
|
|
|
Defines the lookup type, which can be |
A type with only the optional properties from T, optionally nested based on Z.
type Obj = { a: string | undefined; b?: string; c?: { d: string; e?: string } };
// { b?: string; c?: { d: string; e?: string; }; }
type Shallow = ObjectOmitRequired<Obj, 'shallow'>;
// { b?: string; c?: { e?: string; }; }
type Deep = ObjectOmitRequired<Obj, 'deep'>;