使用React Stateless Function组件的TypeScript编译器错误

我试图在TypeScript中编写一个React Stateless Function组件 . 请参阅以下代码:

import * as React from 'react';
import {observer} from 'mobx-react';

export interface LinkProps {
    view: any;
    className: any;
    params?: any;
    queryParams?: any;
    store?: any;
    refresh: boolean;
    style?: any;
    children: any;
    title?: any;
    router: any;
}

const Link: React.SFC<LinkProps> = (   // <----- Error on this line
    {
        view,
        className,
        params = {},
        queryParams = {},
        store = {},
        refresh = false,
        style = {},
        children,
        title = children,
        router = store.router
    }) => {
    ...
}

export default observer(Link);

但是编译器在 const Link 上给出了一个错误:

src / components / Link.tsx(17,7):错误TS2322:输入'{{view,className,params,queryParams,store,refresh,style,children,title,router}:LinkPr ...'不能赋值给类型'StatelessComponent' . 类型'void | Element'不能分配给'ReactElement'类型 . 类型'void'不能分配给'ReactElement'类型 .

我究竟做错了什么?

以下是我的pckage.json文件中的版本依赖项:

"@types/react": "^16.0.29",
"@types/react-dom": "^16.0.3",
"del-cli": "^1.1.0",
"mobx": "^3.4.1",
"mobx-react": "^4.3.5",
"react": "^16.2.0",
"typescript": "^2.6.2"

提前致谢!

回答(0)