反应:缺少函数的返回类型。 eslint(@ typescript-eslint / explicit-function-return-type) [英] React: Missing return type on function. eslint(@typescript-eslint/explicit-function-return-type)

查看:1659
本文介绍了反应:缺少函数的返回类型。 eslint(@ typescript-eslint / explicit-function-return-type)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Typescript React的新手。 eslint在一个非常基本的功能组件中抱怨我缺少该功能组件本身的返回类型。我在哪里错了?

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?

< img src = https://i.stack.imgur.com/YTrDZ.png alt =在此处输入图片描述>

推荐答案

正如Nicholas Tower在此答案中所解释的打字稿|关于函数ESLint缺少返回类型的警告,具体取决于您使用的反应版本,您可以使用以下任意行:

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:

如果您使用的是最新的React版本(16.8.0或更高版本),请执行以下操作:
const组件:React.FunctionComponent< Props> =(道具:道具)=> (

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

在16.8之前,您应该这样做:
const组件:React.SFC<道具> =(道具:道具)=>(

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

SFC代表无状态功能组件。

Where SFC stands for "stateless functional component".

这篇关于反应:缺少函数的返回类型。 eslint(@ typescript-eslint / explicit-function-return-type)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆