import { Tuple, Obj, TypePredicate } from './index'; /** * Defines the type of value, which is passed to `TPromise.then(cb)` `cb` callback. * * @param TPromise Target `Promise` to unpack result from. */ export type UnpackPromise> = ( TPromise extends Promise ? TResult : never ); /** * Defines the type of values of the given `TArray` * * @param TArray Type of array to infer items type from. */ export type UnpackArray = ( TArray extends Array ? TItems : never ); /** * Widens `[T1, T2, T3, ...]` tuple type into an array type `(T1 | T2 | T3 | ...)[]` * @param TTuple Tuple type to widen to array. */ export type TupleToArray = ( TTuple extends Tuple ? TItems[] : never ); /** * Defines `string` or `number` or `boolean` or `Array` that represents * a widened contravariant version of the given unit type `T`. * * @param T Unit type to widen. * * @remarks * * If `T` is a tuple type it is widened to `Array<>` type. * * If `T` is string or number literal or `true` or `false` it gets widened to * `string` or `number` or `boolean` respectivelly. * * If `T` is not a unit type, it is left as it is. */ export type Widen = ( T extends number ? number : T extends boolean ? boolean : T extends string ? string : T extends Tuple ? TupleToArray : T ); /** * Defines a `Widen<>`ed version of `TObj` with all its values widened recursively. * See [[Widen]] * @param TObj Target object (including tuple) type to widen recursively. */ export type DeepWiden = DeepWidenImpl< TObj extends Tuple ? TupleToArray : TObj >; type DeepWidenImpl = { [TKey in keyof TObj]: TObj[TKey] extends infer TVal ? (TVal extends Obj ? DeepWiden : Widen) : never; }; /** * Defines a type that the given `TTypePred` checks its `suspect` to conform to. * * @param TTypePred Target `TypePredicate` function to unpack. */ export type UnpackTypePredicate = ( TTypePred extends TypePredicate ? TTarget : never );