我REACT-STATELESS-COMPONENT在带有TypeScript的项目中有一个。它有一个错误,说,
REACT-STATELESS-COMPONENT
Missing return type on function.eslint(@typescript-eslint/explicit-function-return-type)
我不确定它要我做什么。这是我的代码:
import React, { Fragment} from 'react'; import IProp from 'dto/IProp'; export interface Props { prop?: IProp; } const Component = <T extends object>({ prop }: Props & T) => ( <Fragment> {prop? ( <Fragment> Some Component content.. </Fragment> ) : null} </Fragment> ); LicenseInfo.defaultProps: {}; export default Component;
你能告诉我我需要做什么。我需要阅读有关TS的信息,但目前我根本不了解它。而且我现在不能这样做。
我建议使用react提供的类型;它们将包含返回类型。如果您使用的是版本16.8.0或更高版本的react,请执行以下操作:
const Component: React.FunctionComponent<Props> = (props) => (
或使用速记:
const Component: React.FC<Props> = (props) => (
在16.8之前,您可以:
const Component: React.SFC<Props> = (props) => (
SFC代表“无状态功能组件”。他们更改了名称,因为功能组件不再必须是无状态的。