Typescript useDispatch 'expected 0-1 arguments, but got 2'
See original GitHub issueI read through the similar recent issue from slugs99, but still can’t get Typescript to work.
I’m trying to use the new useDispatch syntax which takes two arguments, like so:
const dispatchFilters = useDispatch(setFilter, 'filters');
I’m using the latest reactn (2.1.4). I went into types/provider.d.ts and it does appear that useDispatch is typed to take two arguments so I’m not sure what is wrong.
Perhaps something in my global.d.ts
file is wrong? I’m using something similar to the default template.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Problem with expected 0 arguments, but got 1 in Redux Toolkit
So your getNames reducer is going to get state where you're trying to get name, you're missing the action (2nd parameter), and you're...
Read more >Expected 0 arguments, but got 1. : r/reduxjs - Reddit
I am new to redux, so I am trying to build a project using regular reducers and actions using typescript, but at the...
Read more >Expected 0 arguments, but got 1 error in TypeScript | bobbyhadz
The error "Expected 0 arguments, but got 1" occurs when we pass an argument to a function that doesn't take any arguments. To...
Read more >Usage With TypeScript - Redux Toolkit
Redux Toolkit is written in TypeScript, and its API is designed to enable great integration with TypeScript applications.
Read more >How to Use Thunks with Redux Toolkit and TypeScript
Let's change our app a bit and, as an example, create a method to load todos from the server and show them. Refactoring#....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m going to close this since it was taken up in the Discord and now lacks context. If you still need help or have a clear Issue/reproduction, feel free to re-open or make a new issue with the context needed to resolve it. 😄
If you don’t use
addReducer
but put your Reducer in yourglobal.d.ts
file, TypeScript won’t complain at compile time, but it shouldn’t do anything at runtime, because that function won’t exist on the global state and isn’t actually being returned byuseDispatch
.There is a Discord channel dedicated to ReactN, linked at the top and bottom of the README. I can’t guarantee that I am available to respond immediately, but I am responding in my free time. 😃