当将prop传递给子组件时,React + Typescript + propTypes.InferProps抛出``此调用没有重载匹配''

时间:2019-11-30 13:10:18

标签: reactjs typescript react-proptypes

我有此代码:

import { Route } from 'react-router'

const layoutPropTypes = {
    component: pt.any,
    path: pt.string.isRequired,
    exact: pt.bool,
}

const DashboardLayoutRoute = ({
    component: Component,
    ...rest
}: InferProps<typeof layoutPropTypes>) => {
    const render = (matchProps: any) => (
        <DashboardLayout>
            <Component {...matchProps} />
        </DashboardLayout>
    );

    return (<Route {...rest} render={render} />);
};

但是TypeScript确实不喜欢我将...rest的道具传递到Route:

enter image description here

如果删除{...rest}部分,没有任何问题。怎么了我不太了解null的来源。

0 个答案:

没有答案