4
0
forked from crowetic/commerce

Added proper type for fetch input

This commit is contained in:
Luis Alvarez 2021-02-08 22:07:26 -05:00
parent 479b30ba5f
commit 016be86d9a
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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<Result> = responseInterface<Result, CommerceError> & {
export type UseData = <
Data = any,
Input = [...any],
FetchInput = unknown,
FetchInput extends HookFetchInput = never,
Result = any,
Body = any
>(