diff --git a/framework/commerce/utils/types.ts b/framework/commerce/utils/types.ts index f6dbe866f..d84ec07f0 100644 --- a/framework/commerce/utils/types.ts +++ b/framework/commerce/utils/types.ts @@ -45,7 +45,11 @@ export type HookFetcherOptions = { method?: string } -export type HookInput = [string, string | number | boolean | undefined][] +export type HookInputValue = string | number | boolean | undefined + +export type HookInput = [string, HookInputValue][] + +export type HookFetchInput = { [k: string]: HookInputValue } export type HookHandler< // Data obj returned by the hook and fetch operation @@ -53,7 +57,7 @@ export type HookHandler< // Input expected by the hook Input = [...any], // Input expected before doing a fetch operation - FetchInput = unknown, + FetchInput extends HookFetchInput = never, // Data returned by the API after a fetch operation Result = any, // Body expected by the API endpoint diff --git a/framework/commerce/utils/use-data-2.ts b/framework/commerce/utils/use-data-2.ts index a5d237aaa..5536bb02c 100644 --- a/framework/commerce/utils/use-data-2.ts +++ b/framework/commerce/utils/use-data-2.ts @@ -1,5 +1,11 @@ import useSWR, { responseInterface } from 'swr' -import type { HookHandler, HookInput, PickRequired, Fetcher } from './types' +import type { + HookHandler, + HookInput, + HookFetchInput, + PickRequired, + Fetcher, +} from './types' import defineProperty from './define-property' import { CommerceError } from './errors' @@ -10,7 +16,7 @@ export type ResponseState = responseInterface & { export type UseData = < Data = any, Input = [...any], - FetchInput = unknown, + FetchInput extends HookFetchInput = never, Result = any, Body = any >(