Skip to content

Commit

Permalink
lib - improve useHook types
Browse files Browse the repository at this point in the history
  • Loading branch information
LankyMoose committed Oct 4, 2024
1 parent 044f829 commit 2158ba6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/lib/src/hooks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,22 @@ type HookCallback<T> = (state: HookCallbackState<T>) => any
let currentHookName: string | null = null
const nestedHookWarnings = new Set<string>()

function useHook<
T extends () => Record<string, unknown>,
U extends HookCallback<ReturnType<T>>,
>(hookName: string, hookInitializer: T, callback: U): ReturnType<U>

function useHook<T extends Record<string, unknown>, U extends HookCallback<T>>(
hookName: string,
hookData: T,
callback: U
): ReturnType<U>

function useHook<
T,
U extends T extends () => any ? HookCallback<ReturnType<T>> : HookCallback<T>,
U extends T extends () => Record<string, unknown>
? HookCallback<ReturnType<T>>
: HookCallback<T>,
>(
hookName: string,
hookDataOrInitializer: Kaioken.Hook<T> | (() => Kaioken.Hook<T>),
Expand Down

0 comments on commit 2158ba6

Please sign in to comment.