import { Obj } from "./objects"; /** * Defines tuple type of `TItems` union type values. * @param TItems Union type of items of the defined tuple. */ export type Tuple = [TItems] | TItems[]; /** * Shorthand for `TTuple[0]`. * @param TTuple Target tuple to get first item from. * * @copyright https://github.com/fightingcat/Typescript4Fun/blob/master/src/tuple.d.ts */ export type TupleFirstItem = TTuple[0]; /** * Defines the type of the last item in `TTuple`. * If `TTuple` is empty, then expands to `undefined`. * @param TTuple Target tuple to get last item from. * * @copyright https://github.com/fightingcat/Typescript4Fun/blob/master/src/tuple.d.ts */ export type TupleLastItem = TTuple[TupleShift['length']]; /** * Removes the first item from `TTuple`. Does nothing if tuple is empty. * * @param TTuple Tuple to remove first item from. * * @copyright https://github.com/fightingcat/Typescript4Fun/blob/master/src/tuple.d.ts */ export type TupleShift = ((...t: TTuple) => void) extends (x: any, ...t: infer TRet) => void ? TRet : never; /** * Removes the last item from `TTuple`. Does nothing if tuple is empty. * * @param TTuple Tuple to remove last item from. */ export type TuplePop = Overwrite, TTuple>; /** * Pushes `TNewFirstItem` item to the front of `TTuple`. * * @param TTuple Tuple to push `TNewFirstItem` to the front. * @param TNewFirstItem Item type to push to the front of `TTuple`. * * @copyright https://github.com/fightingcat/Typescript4Fun/blob/master/src/tuple.d.ts */ export type TupleUnshift = ((x: TNewFirstItem, ...t: TTuple) => void) extends (...t: infer TRet) => void ? TRet : never; /** * Pushes `TNewLastItem` item to the back of `TTuple`. * * @param TTuple Tuple to push `TNewLastItem` to the back. * @param TNewLastItem Item type to push to the back of `TTuple`. * * @copyright https://github.com/fightingcat/Typescript4Fun/blob/master/src/tuple.d.ts */ export type TuplePush = Overwrite, TTuple & Obj>; /** internal */ type Overwrite = { [TTargetKey in keyof TTarget]: TNewValues[TTargetKey] };