Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 514
Hesam Avatar asked Apr 13 '18 01:04

Hesam


People also ask

How to fix “parameter implicitly has an ‘any’ type” error in typescript?

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.

How do I fix parameter 'props' implicitly has an 'any' type?

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.

Does typescript ts7006 implicitly have an “any” type?

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,

How to fix parameter'element'implicitly has an'any'type?

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.


2 Answers

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

like image 100
Christian Alexander Avatar answered Sep 28 '22 05:09

Christian Alexander


For better clarity, following should be the code snippet.

import { Dispatch } from 'redux';

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

const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators({
    // assignment here
});
like image 38
Taranjeet Avatar answered Sep 28 '22 06:09

Taranjeet