带路由器和TypeScript泛型的react-router

时间:2019-01-21 14:45:06

标签: typescript react-router

代码

import { RouteComponentProps, withRouter } from "react-router";
import * as React from "react";

interface Props<T> {
    foo: T;
    children: (foo: T) => React.ReactNode;
}

function Component<T>(props: Props<T> & RouteComponentProps) {
    return props.children(props.foo);
}

export const Bar = withRouter(Component);

错误

TS2345: Argument of type '<T>(props: Props<T> & RouteComponentProps<{}, StaticContext, any>) => ReactNode' is not assignable to parameter of type 'ComponentType<Props<{}> & RouteComponentProps<{}, StaticContext, any>>'.
  Type '<T>(props: Props<T> & RouteComponentProps<{}, StaticContext, any>) => ReactNode' is not assignable to type 'FunctionComponent<Props<{}> & RouteComponentProps<{}, StaticContext, any>>'.
    Type 'ReactNode' is not assignable to type 'ReactElement<any> | null'.
      Type 'undefined' is not assignable to type 'ReactElement<any> | null'.

如何将路由器属性添加到组件保留T?

0 个答案:

没有答案