@@ -3,7 +3,8 @@ import type { MediaType, PathsWithMethod } from "openapi-typescript-helpers";
33import { useCallback , useDebugValue } from "react" ;
44import { type MutatorCallback , type MutatorOptions , useSWRConfig } from "swr" ;
55import type { Exact , PartialDeep } from "type-fest" ;
6- import type { TypesForGetRequest } from "./types.js" ;
6+ import type { TypesForRequest } from "./types.js" ;
7+ import type { DataHttpMethod } from "./query-base.js" ;
78
89// Types are loose here to support ecosystem utilities like `_.isMatch`
910export type CompareFn = ( init : any , partialInit : any ) => boolean ;
@@ -46,15 +47,17 @@ export function createMutateHook<Paths extends {}, IMediaType extends MediaType>
4647
4748 return useCallback (
4849 function mutate <
49- Path extends PathsWithMethod < Paths , "get" > ,
50- R extends TypesForGetRequest < Paths , Path > ,
50+ Path extends PathsWithMethod < Paths , M > ,
51+ R extends TypesForRequest < Paths , Extract < M , keyof Paths [ keyof Paths ] > , Path > ,
5152 Init extends Exact < R [ "Init" ] , Init > ,
53+ Data extends R [ "Data" ] ,
54+ M extends DataHttpMethod = "get" ,
5255 > (
53- [ path , init ] : [ Path , PartialDeep < Init > ?] ,
54- data ?: R [ " Data" ] | Promise < R [ " Data" ] > | MutatorCallback < R [ " Data" ] > ,
55- opts ?: boolean | MutatorOptions < R [ " Data" ] > ,
56+ [ path , init ] : [ Path , ( PartialDeep < Init > & { method ?: M } ) ?] ,
57+ data ?: Data | Promise < Data > | MutatorCallback < Data > ,
58+ opts ?: boolean | ( MutatorOptions < Data > ) ,
5659 ) {
57- return swrMutate < R [ " Data" ] , R [ " Data" ] > (
60+ return swrMutate < Data , Data > (
5861 ( key ) => {
5962 if (
6063 // Must be array
0 commit comments