smart-types-ts
Version:
A collection of _Smart Types_ and _Smart Constructors_ which enable you to be more strict when defining your application's important types/interfaces.
30 lines (29 loc) • 991 B
TypeScript
import * as e from "fp-ts/lib/Either";
import { SmartTypeRefined } from "../utilTypes";
/**
* @category smartType
* @since 0.0.1
*/
export declare type ArrayWithLength<Min extends number, Max extends number, T> = SmartTypeRefined<T[], "ArrayWithLength", {
min: Min;
max: Max;
}>;
/**
* Constructs an ArrayWithLength. First a min and a max must be passed.
*
* Note: This function can throw if invalid min/max arguments are passed!
*
* @example
* import * as e from 'fp-ts/Either'
* import { mkArrayWithLength } from 'smart-types'
*
* assert.deepStrictEqual(mkArrayWithLength(2, 10)([]), e.left("Length not between 2-10"))
* assert.deepStrictEqual(mkArrayWithLength(2, 10)([1, 2, 3]), e.right([1, 2, 3]))
*
* @category smartConstructor
* @since 0.0.1
*/
export declare const mkArrayWithLength: <Min extends number, Max extends number>(min: Min, max: Max) => <T>(arr: T[]) => e.Either<string, SmartTypeRefined<T[], "ArrayWithLength", {
min: Min;
max: Max;
}>>;