TypeScript:2.8.3
@ types / react:16.3.14
当我将组件声明为GlobalMap.getOrElse(x._1, Array())
(别名为JSX.Element
)时,函数组件中的返回类型为React.SFC
。
发生了三个错误:
React.StatelessComponent
TS2322: Type 'Element' is not assignable to type 'StatelessComponent<{}>', Type 'Element' provides no match for the signature '(props: { children?: ReactNode; }, context?: any): ReactElement<any>'
TS2339: Property 'propTypes' does not exist on type '(props: LayoutProps) => StatelessComponent<{}>'
TS2339: Property 'defaultProps' does not exist on type '(props: LayoutProps) => StatelessComponent<{}>'
答案 0 :(得分:1)
返回类型不是组件,函数本身是组件:
const LayoutHeaderItem: React.SFC<LayoutHeaderItemProps> =
(props: LayoutHeaderItemProps) => {
// ...
}
这个问题有点老了,SFC
弃用了FunctionComponent