import type { TypeCastError } from "./Error"; import type { Args, Fn } from "./HKT"; import type { Err, Ok, Result } from "./Result"; import type { All, Any, Eq as EqImpl, Extends, IsAny, IsNever, IsUnknown } from "./helpers"; import type { Show as ShowT } from "./typeclass"; import type { Show } from "./typeclass/Show/Show"; type ShowW = T extends ShowT ? Show : "<>"; /** * [Fn] Cast a value to type `T`. * * Sig: `(x: unknown) => Result` */ export interface As extends Fn<[unknown], Result> { def: ([x]: Args) => typeof x extends T ? Ok : Err< TypeCastError}', but got '${ShowW}' instead.`> >; } /** * [Fn] Force cast a value to type `T`. Return `never` if the cast fails. * * Type safety is **not guaranteed**. * * Sig: `(x: unknown) => T` */ export interface AsUnsafe extends Fn<[unknown], T> { def: ([x]: Args) => typeof x extends T ? typeof x : never; } /** * [Fn] Ask for a value of type `T`. */ export interface Ask extends Fn<[T], T> { def: ([x]: Args) => typeof x; } export interface IsAnyFn extends Fn<[unknown], boolean> { def: ([x]: Args) => IsAny; } export interface IsNeverFn extends Fn<[unknown], boolean> { def: ([x]: Args) => IsNever; } export interface IsUnknownFn extends Fn<[unknown], boolean> { def: ([x]: Args) => IsUnknown; } export interface AllFn extends Fn<[readonly boolean[]], boolean> { def: ([bs]: Args) => All; } export interface AnyFn extends Fn<[readonly boolean[]], boolean> { def: ([bs]: Args) => Any; } export interface EqFn extends Fn<[unknown, unknown], boolean> { def: ([x, y]: Args) => EqImpl; } export interface ExtendsFn extends Fn<[unknown, unknown], boolean> { def: ([y, x]: Args) => Extends; } /** * [Fn] Checks whether `T` exactly equals `U`. * * @example * ```typescript * type R1 = Eq<1, 1>; * // ^?: true * type R2 = Eq<1, number>; * // ^?: false * type R3 = Eq<1, 1 | 2>; * // ^?: false * ``` */ export interface Eq extends Fn<[unknown], boolean> { def: ([x]: Args) => EqImpl; }