反应:缺少函数的返回类型。 eslint(@ typescript-eslint / explicit-function-return-type)

时间:2019-06-09 23:10:37

标签: reactjs typescript eslint

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

enter image description here

2 个答案:

答案 0 :(得分:1)

如Nicholas Tower在此答案Typescript | Warning about Missing Return Type of function, ESLint中所述,根据您使用的反应版本,您可以使用以下任意行:

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

在16.8之前,您可以执行以下操作: const Component: React.SFC<Props> = (props: Props) => (

SFC代表“无状态功能组件”。

答案 1 :(得分:1)

我也遇到过这个问题。

this.idMaterialSeleccionado typeof: number
this.cantidad typeof: string
this.costoUnitario typeof: string
this.subtotal typeof: string

上面的代码给了我同样的问题,然后代码更新如下,然后错误在我的情况下消失

const handleLogout = () => {
router.push('/')
} 

参考链接: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md

相关问题