forked from crowetic/commerce
Added proper type for fetch input
This commit is contained in:
parent
479b30ba5f
commit
016be86d9a
@ -45,7 +45,11 @@ export type HookFetcherOptions = {
|
|||||||
method?: string
|
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<
|
export type HookHandler<
|
||||||
// Data obj returned by the hook and fetch operation
|
// Data obj returned by the hook and fetch operation
|
||||||
@ -53,7 +57,7 @@ export type HookHandler<
|
|||||||
// Input expected by the hook
|
// Input expected by the hook
|
||||||
Input = [...any],
|
Input = [...any],
|
||||||
// Input expected before doing a fetch operation
|
// Input expected before doing a fetch operation
|
||||||
FetchInput = unknown,
|
FetchInput extends HookFetchInput = never,
|
||||||
// Data returned by the API after a fetch operation
|
// Data returned by the API after a fetch operation
|
||||||
Result = any,
|
Result = any,
|
||||||
// Body expected by the API endpoint
|
// Body expected by the API endpoint
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import useSWR, { responseInterface } from 'swr'
|
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 defineProperty from './define-property'
|
||||||
import { CommerceError } from './errors'
|
import { CommerceError } from './errors'
|
||||||
|
|
||||||
@ -10,7 +16,7 @@ export type ResponseState<Result> = responseInterface<Result, CommerceError> & {
|
|||||||
export type UseData = <
|
export type UseData = <
|
||||||
Data = any,
|
Data = any,
|
||||||
Input = [...any],
|
Input = [...any],
|
||||||
FetchInput = unknown,
|
FetchInput extends HookFetchInput = never,
|
||||||
Result = any,
|
Result = any,
|
||||||
Body = any
|
Body = any
|
||||||
>(
|
>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user