The React data fetching library SWR has an example using the library with typescript here. In the example, a fetcher function is defined that wraps fetch and which is then passed to the useSWR
hook to do the actual data fetching.
export default async function fetcher<JSON = any>(
input: RequestInfo,
init?: RequestInit
): Promise<JSON> {
const res = await fetch(input, init)
return res.json()
}
While not immediately clear from the repo, this results in an typescript-eslint warning due to an unexpected any. Below is a screen shot from my editor showing the warning:
I'm a little unclear as to what's the correct way to handle the any
type here? Should I replace it with unknown
? Or should I define a custom type?