i am currently making a simple react application.
this is my index.tsx
import * as React from \'react\';
import * as ReactDOM from \'react-dom\
All you need is to declare the component type properly to include the props type:
interface IMyProps {
myValue: boolean,
}
const MyComponent: React.FC = (props: IMyProps) => {
...
}
export default MyComponent;
Then you can use it as:
import MyComponent from '../MyComponent';
...
return
And voila, typescript is happy. The good thing about it is that typescript is now checking for passing only the parameters they actually exist in the props interface (can prevent typos and so on).
For the standard component it would be something similar to (what's already in Swapnill's example):
class MyComponent extends React.Component{
constructor(props: IMyProps){}
}
export default MyComponent;