如何修复类型无法分配给 React router render prop 的 LibraryManagedAttributes

pav*_*nan 5 reactjs react-router typescript3.0

我最近将所有反应库更新为最新版本及其所有类型。我面临打字稿编译的问题。它是在说

[ts] Type '{ history: History<any>; location: Location<any>; match: match<any>; staticContext?: StaticContext; }' is not assignable to type 'LibraryManagedAttributes<T["component"], Readonly<{ children?: ReactNode; }> & Readonly<{ history: History<any>; location: Location<any>; match: match<any>; staticContext?: StaticContext; }>>'. [2322]
Run Code Online (Sandbox Code Playgroud)
type PrivateRouteProps = UserAuthStore.UserAuthState &
    typeof UserAuthStore.actionCreators &
    RouteProps &
    { component: typeof React.Component };

class PrivateRoute<T extends PrivateRouteProps = PrivateRouteProps> extends React.Component<T, {}> {


    render() {

        let auth = new Auth();

        const {
            isAuthenticated,
            component: Component,
            ...props
        } = this.props

        if (!isAuthenticated) {
            console.log(this.props)
            window.location.href = auth.getAuthorizeUrl(this.props.location!.pathname!)
        }        

        return (
            <Route
                {...props}
                render={props => isAuthenticated ? <Component {...props} />: (<div>Redirecting...</div>)}
            />
        )
    }
}
Run Code Online (Sandbox Code Playgroud)

我在“组件”上遇到错误<Component {...props} />

pav*_*nan 3

我从破坏中删除了组件并像这样铸造了类型

const Component = this.props.component as React.ComponentType<{} & RouteComponentProps<{}>>;

这对我有用。我从这里读到的。 https://github.com/DefinitelyTyped/DefinitelyTyped/issues/17355#issuecomment-310544041