import type {GreaterThan} from '../greater-than.d.ts'; import type {LessThan} from '../less-than.d.ts'; import type {NegativeInfinity, PositiveInfinity} from '../numeric.d.ts'; import type {UnknownArray} from '../unknown-array.d.ts'; /** Infer the length of the given tuple ``. Returns `never` if the given type is an non-fixed-length array like `Array`. @example ``` type Tuple = TupleLength<[string, number, boolean]>; //=> 3 type Array = TupleLength; //=> never // Supports union types. type Union = TupleLength<[] | [1, 2, 3] | Array>; //=> 1 | 3 ``` */ export type TupleLength = // `extends unknown` is used to convert `T` (if `T` is a union type) to // a [distributive conditionaltype](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types)) T extends unknown ? number extends T['length'] ? never // Return never if the given type is an non-flexed-length array like `Array` : T['length'] : never; // Should never happen /** Returns the maximum value from a tuple of integers. Note: - Float numbers are not supported. @example ``` ArrayMax<[1, 2, 5, 3]>; //=> 5 ArrayMax<[1, 2, 5, 3, 99, -1]>; //=> 99 ``` */ export type TupleMax = number extends A[number] ? never : A extends [infer F extends number, ...infer R extends number[]] ? GreaterThan extends true ? TupleMax : TupleMax : Result; /** Returns the minimum value from a tuple of integers. Note: - Float numbers are not supported. @example ``` ArrayMin<[1, 2, 5, 3]>; //=> 1 ArrayMin<[1, 2, 5, 3, -5]>; //=> -5 ``` */ export type TupleMin = number extends A[number] ? never : A extends [infer F extends number, ...infer R extends number[]] ? LessThan extends true ? TupleMin : TupleMin : Result; export {};