Skip to content

Latest commit

 

History

History
72 lines (50 loc) · 1.01 KB

File metadata and controls

72 lines (50 loc) · 1.01 KB

typelab / utils / ArrayOmitRequired

type ArrayOmitRequired<T, OmitHole> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, _ArrayOmitRequired<T, OmitHole>> : never;

Omit the required elements from T type.

Type Parameters

Type Parameter Default type Description

T extends ReadonlyArray

The Array type to omit the required elements from.

OmitHole extends boolean

true

Whether to omit the hole or not. Defaults to true.

Returns

Array with elements of T that are optional.

Example

// [string?, string?]
type Result1 = ArrayOmitRequired<[string, string, string?, string?]>;

// [unknown?, string?, string?]
type Result2 = ArrayOmitRequired<[string, string?, string?], false>;

// never
type Never = ArrayOmitRequired<any>;