/** * @file Array.Types.ts * @author Gage Sorrell * @copyright (c) 2026 Gage Sorrell * @license MIT */ import type { DefinedOnlyOption, MaybeDefinedOption, ReadonlyOption } from "./Array.Internal.mjs"; import type { NoOptions, TOptions } from "../Generic/Option/Option.Types.mjs"; import type { TBuildStaticTArray } from "./Array.Internal.Types.mjs"; import type { TIsNonNegativeInteger } from "../Math/Math.Types.mjs"; /** * An `Array` type, which is optionally customizable via an {@link OptionsType}. * * @template ElementType - The type of the elements in the array. * @template OptionsType - *(Optional)* The {@link Options:type | options type} for this type. */ export type TArray = Options.DefinedOnly extends OptionsType ? Options.MaybeDefined extends OptionsType ? never : Options.Readonly extends OptionsType ? ReadonlyArray> : Array> : Options.MaybeDefined extends OptionsType ? Options.Readonly extends OptionsType ? ReadonlyArray : Array : Options.Readonly extends OptionsType ? ReadonlyArray : Array; /** * The union of all `Array` types exported by the `@sorrell/utilities` {@link Array} * module, as well as the built-in `Array` type. * * @note This union does *not* include {@link TMaybeArray}. * If you wish to include {@link TMaybeArray}, use {@link TArrayTypeUnsafe}. * * @template ElementType - The type of the elements in the array. * @template OptionsType - *(Optional)* The {@link Options:type | options type} for this type. * @template ArraySize - The number of {@link ElementType | ElementTypes} in this `Array`. The * only type in this union that uses this type parameter is {@link TStaticArray}. */ export type TArrayType = TArray | TNonemptyArray | TStaticArray | Array; /** * The union of all `Array` types exported by the `@sorrell/utilities` {@link Array} * module, as well as the built-in `Array` type. * * @note This union includes {@link TMaybeArray}. If you do not wish to include * {@link TMaybeArray} in the union, use {@link TArrayType} instead. * * @template ElementType - The type of the elements in the array. * @template OptionsType - *(Optional)* The {@link Options:type | options type} for this type. * @template ArraySize - The number of {@link ElementType | ElementTypes} in this `Array`. The * only type in this union that uses this type parameter is {@link TStaticArray}. */ export type TArrayTypeUnsafe = TArrayType | TMaybeArray; /** * The union of a given {@link ElementType}, and `Array`. * * @template ElementType - The type of this, or the type of this `Array`. * @template OptionsType - *(Optional)* The {@link Options:type | options type} for this type. */ export type TMaybeArray = ElementType | TArray; /** * The union of a given {@link ElementType}, and `Array`. * * @template ElementType - The type of this, or the type of this `Array`. * @template ArraySize - The number of {@link ElementType | ElementTypes} in this `Array`. * This must be an integer. * @template OptionsType - *(Optional)* The {@link Options:type | options type} for this type. */ export type TStaticArray = ArraySize extends ArraySize ? number extends ArraySize ? TArray : TIsNonNegativeInteger extends true ? TBuildStaticTArray : never : never; /** * An `Array` that is nonempty. * * @template ElementType - The type of the elements in the array. * @template OptionsType - *(Optional)* The {@link Options:type | options type} for this type. */ export type TNonemptyArray = Options.DefinedOnly extends OptionsType ? Options.MaybeDefined extends OptionsType ? never : Options.Readonly extends OptionsType ? readonly [Exclude, ...Array>] : [Exclude, ...Array>] : Options.MaybeDefined extends OptionsType ? Options.Readonly extends OptionsType ? readonly [ElementType | undefined, ...Array] : [ElementType | undefined, ...Array] : Options.Readonly extends OptionsType ? readonly [ElementType, ...Array] : [ElementType, ...Array]; /** * Options for the types defined in the {@link Array} module. * * The only invalid combinations are those that contain both * {@link Options!DefinedOnly} *and* {@link Options!MaybeDefined}. */ export type Options = TOptions; export declare namespace Options { /** * Specifies that the given array type in the `@sorrell/utilities` `Array` module * should use `ReadonlyArray` internally. */ type Readonly = typeof ReadonlyOption; /** Specifies that `undefined` must extend the given `ElementType`. */ type MaybeDefined = typeof MaybeDefinedOption; /** Specifies that the given `ElementType` must *not* include `undefined`. */ type DefinedOnly = typeof DefinedOnlyOption; /** @see {@link NoOptions} */ type None = NoOptions; } /** * The type returned by {@link FilterDefined}. * * @template ElementType - The type of the elements in the array. */ export type FilteredArray = TArray>; //# sourceMappingURL=Array.Types.d.mts.map