typelab / utils / ArrayOptionalElements
type ArrayOptionalElements<T> = T extends ReadonlyArray<infer Elements> ? _IfNotAnyOrNever<T, _ArrayOptionalElements<T, Elements>> : never;Get the optional elements from T type.
| Type Parameter | Description |
|---|---|
|
|
The |
The elements of T that are optional.
// 1 | 2 | undefined
type Result1 = ArrayOptionalElements<[0, 1?, 2?]>;
// string | undefined
type Result2 = ArrayOptionalElements<(string | undefined)[]>;
// never
type Never1 = ArrayOptionalElements<[0, 1, 2]>;
// never
type Never2 = ArrayOptionalElements<any>;