Skip to content
Advertisement

What is the difference between App: React.FunctionComponent and App = (): React.FunctionComponent?

Trying to understand typescript at the moment.

What is the difference between:

JavaScript

and:

JavaScript

The second one throws an error:

JavaScript

Advertisement

Answer

JavaScript

means that App is a type of React.FunctionComponent<CustomProps>

JavaScript

means that your App is the type of any because you didn’t assign a type but it returns an object of type React.FuctionComponent

The error means that you return a JSX.Element and you said that the function return a FunctionComponent

The right code is :

JavaScript

In addition, you can see directly what type your function is returned if you writte nothing on the return type. Is you have VS code you can hover your mouse on your function and it will display what it returns thanks to the intellisense

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement