UNPKG

typedash

Version:

modern, type-safe collection of utility functions

54 lines (51 loc) 1.71 kB
import { M as Many } from '../Many-Dnn8Ysh_.js'; import { M as Maybe } from '../Maybe-D6dwMjD9.js'; declare const isArray: IsArray; interface IsArray { /** * The same as `Array.isArray` but with a better type guard. * @param value The value to check. * @returns `true` if the value is an array, `false` otherwise. * @example * ```ts * isArray([1, 2, 3]) // true * isArray('foo') // false * ``` */ <T>(value: Maybe<Array<ArrayElement<T>>>): value is NonNullable<typeof value>; /** * The same as `Array.isArray` but with a better type guard. * @param value The value to check. * @returns `true` if the value is an array, `false` otherwise. * @example * ```ts * isArray([1, 2, 3]) // true * isArray('foo') // false * ``` */ <T>(value: Maybe<ReadonlyArray<ArrayElement<T>>>): value is NonNullable<typeof value>; /** * The same as `Array.isArray` but with a better type guard. * @param value The value to check. * @returns `true` if the value is an array, `false` otherwise. * @example * ```ts * isArray([1, 2, 3]) // true * isArray('foo') // false * ``` */ <T>(value: Maybe<Many<T>>): value is NonNullable<readonly T[]>; /** * The same as `Array.isArray` but with a better type guard. * @param value The value to check. * @returns `true` if the value is an array, `false` otherwise. * @example * ```ts * isArray([1, 2, 3]) // true * isArray('foo') // false * ``` */ <T>(value: unknown): value is readonly T[]; } type ArrayElement<T> = T extends ReadonlyArray<infer U> ? U : never; export { isArray };