typelab / utils / ArrayUnshift
type ArrayUnshift<T, U> = T extends WritableArray ? _IfNotAnyOrNever<T, IfNever<U, T, [U, ...T]>> : never;Adds a new element to the beginning of an Writable Array type.
| Type Parameter | Description |
|---|---|
|
|
The |
|
|
The element type to add to the front of the |
A new Array type with the element U added to the front.
// [boolean, string, number]
type Unshifted = ArrayUnshift<[string, number], boolean>;
// [string, number]
type Same = ArrayUnshift<[string, number], never>;
// never
type Never1 = ArrayPush<readonly [string, number], string>;
// never
type Never2 = ArrayPush<any, string>;