Skip to content

Commit

Permalink
hooks types update
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed May 22, 2024
1 parent cde1fa0 commit b47d18b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/types/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
interface Parameter<T extends any[], R> {
fn: (...args: T) => R;
// Define a generic type for functions with specific parameters and return type
export type AnyFunction<P extends unknown[] = never[], R = unknown> = (
...args: P
) => R;

// Define a generic type for a dictionary of functions
export type Functions = {
[key: string]: AnyFunction;
};

// Define a parameter interface to wrap the function and its result
interface Parameter<P extends unknown[], R> {
fn: (...args: P) => R;
result?: R;
}

export type HookFn<T extends (...args: any[]) => any> = (
// Define the HookFn type using generics for better type safety
export type HookFn<T extends AnyFunction> = (
params: Parameter<Parameters<T>, ReturnType<T>>,
...args: Parameters<T>
) => ReturnType<T>;

export type Function = (...args: any[]) => any;
export type Functions = {
[key: string]: Function;
};

0 comments on commit b47d18b

Please sign in to comment.