typelab / utils / ObjectOmitOptional
type ObjectOmitOptional<T, Z> = IsObjectLiteral<T> extends true ? { [K in keyof T as IsRequiredProperty<T, K> extends true ? K : never]-?: _Lookup<Z, { shallow: T[K]; deep: ObjectOmitOptional<T[K]> }> } : T;Get the required 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 required properties from T, optionally nested based on Z.
type Obj = { a: string | undefined; b?: string; c: { d: string, e?: string } };
// { a: string | undefined; c: { d: string; e?: string } }
type Shallow = ObjectOmitOptional<Obj, 'shallow'>;
// { a: string | undefined; c: { d: string; }}
type Deep = ObjectOmitOptional<Obj, 'deep'>;