import { If } from "./if"; import { IsNever } from "./never"; /** * Returns the first argument if it is an empty array, otherwise returns `never` * @example * ```ts * // never * type Result = EmptyArray<[1]> * ``` */ export type EmptyArray = T extends readonly [ unknown, ...unknown[] ] ? never : T; /** * Returns the first argument if it is a non empty array, otherwise returns `never` * @example * ```ts * // never * type Result = EmptyArray<[1]> * ``` */ export type NonEmptyArray = If< IsNever>, T, never >; /** * Returns a boolean whether the passed argument is an empty array * @example * ```ts * // false * type Result - IsEmptyArray<[1]> */ export type IsEmptyArray = If< IsNever>, false, true >; /** * Returns a boolean whether the passed argument is a non empty array * @example * ```ts * // true * type Result - IsEmptyArray<[1]> */ export type IsNonEmptyArray = If< IsNever>, true, false >; /** * Returns the second argument if the first argument is an empty array (defaults to `true`), otherwise returns the third argument (defaults to `false`) * @example * ```ts * // string * type Result = IfEmptyArray<[], string, number> * ``` */ export type IfEmptyArray< T extends readonly unknown[], IfTrue = true, IfFalse = false > = If, IfTrue, IfFalse>; /** * Returns the second argument if the first argument is a non empty array (defaults to `true`), otherwise returns the third argument (defaults to `false`) * @example * ```ts * // string * type Result = IfEmptyArray<[1], string, number> * ``` */ export type IfNonEmptyArray< T extends readonly unknown[], IfTrue = true, IfFalse = false > = If, IfTrue, IfFalse>;