Type error when overriding global fetcher function with null
Author: rickythefoxCreated Feb 8, 2024Updated Jul 12, 2026
Labelsbug
Bug report
Description / Observed Behavior
When a global fetcher is configured using SWRConfig it can't be overridden locally by setting fetcher to null - a request still happens.
// This results in a request to "/state"
const first = useSWR("state", null);If I set the fetcher to null in the config parameter it works, but that does not typecheck so a ts-ignore comment is needed.
// This works but TS complains:
// "Type 'null' is not assignable to type '((arg: "state") => any) | undefined'."
const second = useSWR("state2", null, {
fetcher: null,
});
A workaround is to type the config as {}:
useSWR<DataType, ErrorType, {}>("state2", null, {
fetcher: null,
});
Expected Behavior
No typescript errors displayed. In best case a null passed as fetcher should override global config.
Repro Steps / Code Example
https://codesandbox.io/p/sandbox/useswr-typing-bug-2d4prc?file=%2Fsrc%2FApp.tsx%3A10%2C32
Additional Context
SWR version 2.2.4
Source: vercel/swr