jaydenseric / graphql-react

A GraphQL client for React using modern context and hooks APIs that is lightweight (< 4 kB) but powerful; the first Relay and Apollo alternative with server side rendering.
https://npm.im/graphql-react
MIT License
717 stars 22 forks source link

Type 'Dispatch<any>' is not assignable to type '() => void' #62

Open bandinopla opened 1 day ago

bandinopla commented 1 day ago

The jsdoc says this function returns: https://github.com/jaydenseric/graphql-react/blob/38a7abcebf7e6d0e4e821c5c3982e8c1cbfae67e/useForceUpdate.mjs#L7

but then here: https://github.com/jaydenseric/graphql-react/blob/38a7abcebf7e6d0e4e821c5c3982e8c1cbfae67e/useForceUpdate.mjs#L12

It grabs the dispatch from React.useReducer which expects an action... https://es.react.dev/reference/react/useReducer#dispatch

This makes typescript cry: Target signature provides too few arguments. Expected 1 or more, but got 0.

I have set skipLibCheck to true but still get this error. I'm using vite... any ideas?

https://github.com/jaydenseric/graphql-react/pull/63

jaydenseric commented 1 day ago

I've done a type check on the useForceUpdate.mjs module with the latest version of TypeScript and @types packages installed, and can't see any errors. Can you please share what version of each of these you have installed:

Also, can you please check if something in your project TS config is different to here, and share what changes to it reproduce the error?

https://github.com/jaydenseric/graphql-react/blob/38a7abcebf7e6d0e4e821c5c3982e8c1cbfae67e/jsconfig.json#L1-L11

jaydenseric commented 1 day ago

Note that the hook returns the type React.DispatchWithoutAction, which is a legit thing to do and that type comes from @types/react:

Screenshot 2024-09-27 at 10 29 40 am Screenshot 2024-09-27 at 10 30 26 am