@@ -248,12 +248,14 @@ const generateSwrMutationArguments = ({
248
248
operationName,
249
249
isRequestOptions,
250
250
mutator,
251
+ swrBodyType,
251
252
} : {
252
253
operationName : string ;
253
254
isRequestOptions : boolean ;
254
255
mutator ?: GeneratorMutator ;
256
+ swrBodyType : string ;
255
257
} ) => {
256
- const definition = `SWRMutationConfiguration<Awaited<ReturnType<typeof ${ operationName } >>, TError, string, Arguments , Awaited<ReturnType<typeof ${ operationName } >>> & { swrKey?: string }` ;
258
+ const definition = `SWRMutationConfiguration<Awaited<ReturnType<typeof ${ operationName } >>, TError, string, ${ swrBodyType } , Awaited<ReturnType<typeof ${ operationName } >>> & { swrKey?: string }` ;
257
259
258
260
if ( ! isRequestOptions ) {
259
261
return `swrOptions?: ${ definition } ` ;
@@ -448,6 +450,7 @@ const generateSwrMutationImplementation = ({
448
450
mutator,
449
451
swrOptions,
450
452
doc,
453
+ swrBodyType,
451
454
} : {
452
455
isRequestOptions : boolean ;
453
456
operationName : string ;
@@ -461,6 +464,7 @@ const generateSwrMutationImplementation = ({
461
464
mutator ?: GeneratorMutator ;
462
465
swrOptions : SwrOptions ;
463
466
doc ?: string ;
467
+ swrBodyType : string ;
464
468
} ) => {
465
469
const hasParamReservedWord = props . some (
466
470
( prop : GetterProp ) => prop . name === 'query' ,
@@ -488,6 +492,7 @@ ${doc}export const ${camel(`use-${operationName}`)} = <TError = ${errorType}>(
488
492
operationName,
489
493
isRequestOptions,
490
494
mutator,
495
+ swrBodyType,
491
496
} ) } ) => {
492
497
493
498
${
@@ -659,7 +664,7 @@ export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${
659
664
if ( prop . type === GetterPropType . NAMED_PATH_PARAMS ) {
660
665
return prop . destructured ;
661
666
} else if ( prop . type === GetterPropType . BODY ) {
662
- return `arg as ${ prop . implementation . split ( ': ' ) [ 1 ] } ` ;
667
+ return `arg` ;
663
668
} else {
664
669
return prop . name ;
665
670
}
@@ -699,9 +704,14 @@ export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${
699
704
? '{ arg }'
700
705
: '__' ;
701
706
707
+ const swrBodyType =
708
+ props
709
+ . find ( ( prop ) => prop . type === GetterPropType . BODY )
710
+ ?. implementation . split ( ': ' ) [ 1 ] ?? 'Arguments' ;
711
+
702
712
const swrMutationFetcherFn = `
703
713
export const ${ swrMutationFetcherName } = (${ swrProps } ${ swrMutationFetcherOptions } ) => {
704
- return (_: string, ${ swrMutationFetcherArg } : { arg: Arguments }): ${ swrMutationFetcherType } => {
714
+ return (_: string, ${ swrMutationFetcherArg } : { arg: ${ swrBodyType } }): ${ swrMutationFetcherType } => {
705
715
return ${ operationName } (${ httpFnProperties } ${
706
716
swrMutationFetcherOptions . length
707
717
? ( httpFnProperties . length ? ', ' : '' ) + 'options'
@@ -723,6 +733,7 @@ export const ${swrMutationFetcherName} = (${swrProps} ${swrMutationFetcherOption
723
733
mutator,
724
734
swrOptions : override . swr ,
725
735
doc,
736
+ swrBodyType,
726
737
} ) ;
727
738
728
739
return swrMutationFetcherFn + swrMutationKeyFn + swrImplementation ;
0 commit comments