diff --git a/packages/swr/src/index.ts b/packages/swr/src/index.ts index a6772230d..5b8f2fc6c 100644 --- a/packages/swr/src/index.ts +++ b/packages/swr/src/index.ts @@ -552,7 +552,7 @@ const generateSwrHook = ( summary, deprecated, }: GeneratorVerbOptions, - { route }: GeneratorOptions, + { route, context }: GeneratorOptions, ) => { const isRequestOptions = override?.requestOptions !== false; const doc = jsDoc({ summary, deprecated }); @@ -695,8 +695,15 @@ export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${ const swrMutationFetcherType = mutator ? `Promise<${response.definition.success || 'unknown'}>` : `Promise>`; + const swrMutationFetcherOptionType = !mutator + ? 'AxiosRequestConfig' + : mutator.hasSecondArg + ? `SecondParameter` + : ''; const swrMutationFetcherOptions = - !mutator && isRequestOptions ? 'options?: AxiosRequestConfig' : ''; + isRequestOptions && swrMutationFetcherOptionType + ? `options${context.output.optionsParamRequired ? '' : '?'}: ${swrMutationFetcherOptionType}` + : ''; const swrMutationFetcherArg = props.some( (prop) => prop.type === GetterPropType.BODY, diff --git a/tests/configs/swr.config.ts b/tests/configs/swr.config.ts index 0e2a33c6e..a8e659afd 100644 --- a/tests/configs/swr.config.ts +++ b/tests/configs/swr.config.ts @@ -59,7 +59,7 @@ export default defineConfig({ mock: true, override: { mutator: { - path: '../mutators/custom-instance.ts', + path: '../mutators/multi-arguments.ts', name: 'customInstance', }, }, @@ -73,8 +73,8 @@ export default defineConfig({ }, customClient: { output: { - target: '../generated/swr/mutator/endpoints.ts', - schemas: '../generated/swr/mutator/model', + target: '../generated/swr/custom-client/endpoints.ts', + schemas: '../generated/swr/custom-client/model', client: 'swr', mock: true, override: {