react/typescript: Parameter 'props' implicitly has an 'any' type error
in type script you need to specify the type of props you are going to send or it takes the default type defined tin @types/react. if you dont want to specify any type then explicitly ask the component to expect state and props of 'any' type.
class FormExample extends React.Component<any,any> {
the first type argument is for defining the type of props you are expecting , the other is for type of state of the component.
In typeScript you should install @types/react and while extending the React.Component
you need to specify the props
and state
types.
Here is the example
import * as React from 'react'
interface Props {
... // your props validation
}
interface State {
... // state types
}
class FormExample extends React.Component<Props, State> {... }
Specifying the type of the constructor parameter resolved this issue in my case.
class Clock extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
}
I just got this error on a functional component.
In order to get information such as props.children
as well as custom props, you should do the following.
import { FunctionComponent } from 'react';
const Layout: FunctionComponent<{ hello: string }> = props => (
<div style={layoutStyle}>
<Header />
{props.hello}
{props.children}
</div>
);