import { ClassType } from './Class.types'; /** * A dictionary type that maps string keys to values of type `T`. * * @template T - The type of the values in the dictionary. Defaults to `unknown`. */ export type Dict = Record; /** * Represents a dictionary where the keys are strings and the values are dictionaries of type `Dict`. * * @template T - The type of the values in the inner dictionary. * @template S - The type of the keys in the outer dictionary, defaults to `string`. */ export type DoubleDict = Record>; /** An alias for `Object` */ export type Obj = Record; /** An empty `Object` equivalent to `{}` */ export type EmptyObj = Dict; /** * Extracts the keys from an object type `T` whose values match the type `V`. * * This utility type iterates over the keys of `T` and includes only those keys * whose corresponding values are assignable to the type `V`. * * @template T - The object type or class type to extract keys from. * @template V - The type to match the values against. * * @example * ```typescript * type Example = { * name: string; * age: number; * isActive: boolean; * }; * * // Result: "name" | "isActive" * type StringKeys = KeysMatching; * ``` */ export type KeysMatching = { [K in keyof T]-?: T[K] extends V ? K : never; }[keyof T]; /** * Constructs a type by excluding keys from the given type `T` whose values extend the type `V`. * * @template T - The type from which keys are to be excluded. It can be an object type or a class type. * @template V - The type that, if matched by a value in `T`, will cause the corresponding key to be excluded. * * @example * ```typescript * type Example = { * a: string; * b: number; * c: boolean; * }; * * type Result = KeysExcluding; // Result will be "b" | "c" * ``` */ export type KeysExcluding = { [K in keyof T]-?: T[K] extends V ? never : K; }[keyof T]; /** Returns he keys of values that are arrays in an `Object` */ export type KeysOfArrays = KeysMatching; /** Returns the common properties of two objects [intersection] */ export type MappedCommon = { [K in keyof A & keyof B]: A[K] extends B[K] ? never : K; }; /** Creates a type with just the optional values of an object */ export type OptionalKeys = MappedCommon>[keyof T]; /** Creates a type to define optional or default values */ export type DefaultProps = Partial<{ [K in OptionalKeys]: T[K]; }>; /** A class that requires no constructor arguments */ export type Instantiable = new () => T; /** Returns the values of an object */ export type ValuesOf = T[keyof T]; /** A value that can be used as key in an `Object` */ export type ObjectKey = string | number | symbol; /** * A utility type that makes all properties of a given type `T` mutable (i.e., removes the `readonly` modifier). * * @template T - The type whose properties should be made mutable. */ export type Mutable = { -readonly [P in keyof T]: T[P]; }; /** * A utility type that recursively makes all properties of an object mutable. * * @template T - The type of the object to be made deeply mutable. */ export type DeepMutable = { -readonly [P in keyof T]: DeepMutable; }; /** * A utility type that ensures all keys of the given type `T` are strings. * If `T` has only string keys, it returns the keys of `T`. * Otherwise, it returns `never`. * * @template T - The type to be checked for string keys. */ export type AssertStringKeys = keyof T extends string ? keyof T : never;