import type { Chronos } from '../date/Chronos'; import type { DateLike } from '../date/types'; /** Uncontrolled any to use for edge cases */ export type Any = any; declare const __brand: unique symbol; type $Brand = { [__brand]: B; }; /** * * Creates a branded version of a base type by intersecting it with a unique compile-time marker. * * @param T - Base type to brand. * @param B - Brand identifier used to distinguish this type from structurally similar types. * @remarks Useful for preventing accidental mixing of structurally identical types, while keeping the runtime value unchanged. * * @example * type UserId = Branded; * const id = 'abc123' as UserId; */ export type Branded = T & $Brand; /** Represents a value that may or may not be present. */ export type Maybe = T | undefined; /** Utility type to flatten Partial type */ export type FlattenPartial = Partial<{ [K in keyof T]: T[K]; }>; /** Union of `number` and numeric string */ export type Numeric = number | `${number}`; /** Union of Basic Primitive Types (i.e. `string | number | boolean`) */ export type BasicPrimitive = string | number | boolean; /** `null` or `undefined` */ export type NullOrUndefined = null | undefined; /** Union of All Primitive Types (i.e. `string | number | boolean | symbol | bigint | null | undefined`) */ export type Primitive = string | number | boolean | symbol | bigint | null | undefined; /** Union of Normal Primitive Types (i.e. `string | number | boolean | null | undefined`) */ export type NormalPrimitive = string | number | boolean | null | undefined; /** Extract normal primitive key(s) (i.e. `string | number | boolean | null | undefined`) from an object */ export type NormalPrimitiveKey = { [K in keyof T]: T[K] extends NormalPrimitive ? K : never; }[keyof T]; /** * * Keys of an object that are part of the object type itself. * This excludes keys that are inherited from the prototype chain. * This type is useful for extracting keys that are part of the object's own properties. * It is used in the `OwnKeys` type to filter out keys that are not part of the object properties. */ export type OwnKeys = { [K in keyof T]: {} extends Pick ? never : K; }[keyof T]; /** Extract primitive (string, number or boolean) key(s) from an object */ export type NonNullishPrimitiveKey = { [K in keyof T]: T[K] extends BasicPrimitive ? K : never; }[keyof T]; /** Falsy primitive type */ export type FalsyPrimitive = false | '' | 0 | null | undefined; /** A generic class constructor */ export type Constructor = new (...args: any[]) => any; /** Generic function type */ export type GenericFn = (...args: any[]) => any; /** Generic function type that returns `void` */ export type VoidFn = (...args: any[]) => void; /** Delayed (debounced or throttled) function type after certain delay */ export type DelayedFn = (...args: Parameters) => void; export type { DelayedFn as ThrottledFn, VoidFn as VoidFunction }; /** Asynchronous function type */ export type AsyncFunction = (...args: any[]) => Promise; /** Advanced types to exclude from counting as object key */ export type AdvancedTypes = Array | File | FileList | Chronos | DateLike | Blob | Date | RegExp | WeakMap | WeakSet | Map | Set | Function | GenericFn | VoidFn | AsyncFunction | Promise | Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | bigint | symbol; /** Helper to detect if a type has methods */ export type HasMethods = { [K in keyof T]: T[K] extends Function ? true : never; }[keyof T] extends never ? false : true; /** * Represents detailed information about a class's methods. */ export interface ClassDetails { /** * List of instance method names defined directly on the class prototype. */ instanceMethods: string[]; /** * List of static method names defined directly on the class constructor. */ staticMethods: string[]; /** * List of instance getter names defined directly on the class prototype. */ instanceGetters: string[]; /** * List of static getter names defined directly on the class constructor. */ staticGetters: string[]; /** * Number of instance methods. */ instanceCount: number; /** * Number of static methods. */ staticCount: number; /** * Total number of instance and static getters combined. */ totalGetters: number; /** * Total number of instance and static methods combined. */ totalMethods: number; } /** Literal type for `partial` and `required` */ export type PartialOrRequired = 'partial' | 'required'; /** * - Utility type to assert that a given type condition evaluates to `true`. * * @remarks * - This type is mainly used in **type-level tests** to enforce that a condition (usually produced by {@link Equal}) is satisfied. * - If the condition is not `true`, TypeScript will raise an error at compile time. * * @example * // Passes ✅ * type Test1 = Expect; * * // Fails ❌ - will cause a type error * type Test2 = Expect; */ export type Expect = T; /** * * Utility type that checks whether two types `X` and `Y` are strictly equal. * * @remarks * - This type uses conditional types and generic inference tricks to compare whether two types are identical. * - It resolves to `true` if `X` and `Y` are the same type, otherwise `false`. * * _Typically used together with {@link Expect} for type-level assertions in tests._ * * @example * type Test1 = Equal; // true * type Test2 = Equal; // false * * // Example with Expect * type Check = Expect>; // ✅ Compiles * type Fail = Expect>; // ❌ Type error */ export type Equal = (() => T extends X ? 1 : 2) extends () => (T extends Y ? 1 : 2) ? true : false; /** * * Ensures that an array has **at least one element**. * * @remarks * - This type enforces non-empty arrays by requiring the first element `T`, followed by zero or more additional `T`s. * * @example * type NonEmpty = ValidArray; // [number, ...number[]] * const arr1: NonEmpty = [1]; // ✅ OK * const arr2: NonEmpty = []; // ❌ Error (empty array not allowed) */ export type ValidArray = [T, ...Array]; /** * * A readonly array of elements of type `T`. * * @remarks * - Shorthand for `ReadonlyArray`. Used to represent immutable lists. * * @example * type Numbers = List; // readonly number[] * const arr: Numbers = [1, 2, 3]; // ✅ OK * arr.push(4); // ❌ Error (readonly) */ export type List = ReadonlyArray; /** Function type for serializing a value of type `T` to a string. */ export type Serializer = (value: T) => string; /** Function type for deserializing a string to a value of type `T`. */ export type Deserializer = (value: string) => T;