1 export type Callback<T extends any[] = any[], R = any> = (...args: T) => R;
2 export type AsyncCallback<T extends any[] = any[], R extends Promise<any> = Promise<any>> = (...args: T) => R;
4 export type Maybe<T> = T | undefined;
5 export type MaybeNull<T> = T | null;
6 export type MaybeArray<T> = T | T[];
7 export type MaybePromise<T> = T | Promise<T>;
8 export type Unpack<T> = T extends (infer U)[] ? U : T extends readonly (infer U)[] ? U : never;
10 /** Adds a phantom type tag to a base type without affecting its runtime structure.
11 * This allows for type-level discrimination and specialization while maintaining
12 * the original type's shape */
13 export type Tagged<Base, TagType> = Base & { readonly __tag__?: TagType };
14 /** Conditional type that resolves to different types based on whether the input type
15 * has a specific tag. This enables type-level branching based on phantom types. */
16 export type TagMatch<T, Tag, WhenTagged, WhenUntagged> = T extends { __tag__?: Tag } ? WhenTagged : WhenUntagged;
18 export type RequiredNonNull<T, K extends keyof T = keyof T> = Omit<T, K> & {
19 [P in K]-?: P extends K ? NonNullable<T[P]> : T[P];
21 export type RequiredProps<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };
22 export type RecursivePartial<T> = { [P in keyof T]?: RecursivePartial<T[P]> };
23 export type OptionalProp<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
24 export type ExtractKeysOfType<T, U> = { [K in keyof T]: T[K] extends U ? K : never }[keyof T];
25 export type DefinedPropertiesOnly<S extends {}> = Pick<S, DefinedKeys<S>>;
26 export type DefinedKeys<S extends {}, K = keyof S> = Extract<
28 K extends keyof S ? (S[K] extends undefined ? never : K) : never
31 /** This type transformer iterates over each property of T and checks if its type
32 * matches any of the OriginalTypes in U. If a match is found, the property's type
33 * is replaced with the corresponding NewType. If no match is found, the property's
34 * type remains unchanged. */
35 export type TypeMapper<T, U extends [unknown, unknown][]> = T extends U[number][0]
36 ? Extract<U[number], [T, unknown]>[1]
37 : T extends (infer A)[]
39 : T extends Record<any, any>
40 ? { [K in keyof T]: TypeMapper<T[K], U> }
43 export type ColorRGB = `${number} ${number} ${number}`;