swr icon indicating copy to clipboard operation
swr copied to clipboard

useSWRMutation - Type error: Expected 2-3 arguments, but got 1.

Open mindsworth opened this issue 3 months ago • 1 comments

info: v2.2.5

Bug report

I am not really sure if it's bug but I believe it to be a type bug.

Description / Observed Behavior

In my current project Nextjs 14.1.4, Typescript 5. I have successfully setup swr with global swrConfig where I have added the fetcher and all is perfectly working as expected, except the type error Type error: Expected 2-3 arguments, but got 1. that I'm getting since I am not passing the fetcher option.

Screenshot 2024-03-22 at 11 34 40

Is there how I can extend the type declaration to make fetcher optional?

Thanks for the good work, SWR is a great tool.

Note: The code is working as expected, just the type.

mindsworth avatar Mar 22 '24 10:03 mindsworth

After spending some time on this I was able to extend the type by adding the following line to this file swr.d.ts;

Screenshot 2024-03-22 at 14 57 34

But it will be cool if this can be made optional here

mindsworth avatar Mar 22 '24 14:03 mindsworth