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?
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.
To fix the "parameter implicitly has an ‘any’ type" error in TypeScript, we can set the noImplicitAny option to false in tsconfig.json. to set the noImplicitAny option to false in tsconfig.json. Now the "parameter implicitly has an ‘any’ type" error shouldn’t be showing for untyped variables.
The React.js error "Parameter 'props' implicitly has an 'any' type" occurs when we don't type the props of a function or class component or forget to install typings for React. To solve the error explicitly set a type for the props object in your components.
This article is a fix of a popular Angular exception: Typescript TS7006: Parameter 'xxxx' implicitly has an 'any' type. We can see tons of articles discussion online about this exception, we quote several here,
if you get an error as Parameter 'element' implicitly has an 'any' type.Vetur (7006) in vueJs you can fixed it by defining thoes variables as any as follow.
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
For better clarity, following should be the code snippet.
import { Dispatch } from 'redux';
//..... code
//..... code
const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators({
// assignment here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With