Hesam
Hesam

Reputation: 53600

Parameter 'dispatch' implicitly has an 'any' type

I have recently changed my JS based project to TypeScript. I am getting following lint issue and I don't know what is the type of dispatch. I am wondering what it is?

enter image description here

I know I am able to tell tslint to ignore this checking by "noImplicitAny": false in tsconfig file. However, I am not sure this is good way to do that or not.

Upvotes: 18

Views: 14881

Answers (2)

Christian Alexander
Christian Alexander

Reputation: 296

Dispatch is defined in @types/react-redux as

type Dispatch<S> = Redux.Dispatch<S>;

When I encountered this error message in the past, I simply had to install the @types/react-redux package.

You will likely find that many projects do not contain typings files. Luckily, the @types packages on NPM exist. They are maintained by the community at https://github.com/DefinitelyTyped/DefinitelyTyped

Upvotes: 12

Taranjeet
Taranjeet

Reputation: 581

For better clarity, following should be the code snippet.

import { Dispatch } from 'redux';

//..... code
//..... code

const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators({
    // assignment here
});

Upvotes: 26

Related Questions