From 2158ba641b36795d2cb358610b1a4905d3944050 Mon Sep 17 00:00:00 2001 From: Robby6Strings Date: Fri, 4 Oct 2024 18:34:52 +1300 Subject: [PATCH] lib - improve `useHook` types --- packages/lib/src/hooks/utils.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/lib/src/hooks/utils.ts b/packages/lib/src/hooks/utils.ts index a204033..9f7fe7d 100644 --- a/packages/lib/src/hooks/utils.ts +++ b/packages/lib/src/hooks/utils.ts @@ -78,9 +78,22 @@ type HookCallback = (state: HookCallbackState) => any let currentHookName: string | null = null const nestedHookWarnings = new Set() +function useHook< + T extends () => Record, + U extends HookCallback>, +>(hookName: string, hookInitializer: T, callback: U): ReturnType + +function useHook, U extends HookCallback>( + hookName: string, + hookData: T, + callback: U +): ReturnType + function useHook< T, - U extends T extends () => any ? HookCallback> : HookCallback, + U extends T extends () => Record + ? HookCallback> + : HookCallback, >( hookName: string, hookDataOrInitializer: Kaioken.Hook | (() => Kaioken.Hook),