Redux TS Generic type 'Dispatch' requires 1 type argument(s)

前端 未结 2 723
不思量自难忘°
不思量自难忘° 2020-12-21 04:54

Trying to setup a project with typescript and redux. I am getting this error

Generic type \'Dispatch\' requires 1 type argument(s).
<
相关标签:
2条回答
  • 2020-12-21 05:03

    I solved this by downgrading to Redux 3.7. It has proper typings (There still aren't typings for Redux 4.0). There are some Github issues where they discuss about it (here and here).

    0 讨论(0)
  • 2020-12-21 05:21

    It looks to me like you are indeed facing the same issue you linked. While we wait and see if 7mllm7's pull request is merged, you can use his modified version of the react-redux types. I'd recommend the following approach:

    1. git clone --depth=1 https://github.com/7mllm7/DefinitelyTyped
    2. Copy the types/react-redux folder into your project (suppose for example you copy it to a folder named react-redux.fixed).
    3. Edit react-redux.fixed/package.json to replace "private": "true" with "name": "@types/react-redux".
    4. In your package.json, specify the version of @types/react-redux as ./react-redux.fixed.
    5. Run npm install. npm will make a symlink from node_modules/@types/react-redux to react-redux.fixed.

    Compared to just editing the file in node_modules/@types/react-redux, this way npm knows you are using a modified version of the package and won't overwrite it. (This process deserves to be widely known; I'll find a better place to document it if I have time.)

    0 讨论(0)
提交回复
热议问题