React: Missing return type on function. eslint(@typescript-eslint/explicit-function-return-type)

柔情痞子 提交于 2020-05-17 07:47:05

问题


I'm new to Typescript React. In a really basic functional component, eslint is complaining me it's missing the returned type for the functional component itself. Where I'm wrong?


回答1:


As explained by Nicholas Tower in this answer Typescript | Warning about Missing Return Type of function, ESLint, depending on the react version that you are using, you can use any of the lines below:

If you're on the latest react version (16.8.0 or later), do this: const Component: React.FunctionComponent<Props> = (props: Props) => (

Prior to 16.8, you'd instead do: const Component: React.SFC<Props> = (props: Props) => (

Where SFC stands for "stateless functional component".



来源:https://stackoverflow.com/questions/56519019/react-missing-return-type-on-function-eslinttypescript-eslint-explicit-funct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!