我在React中有一个用纯JavaScript编写的类组件:
class Auth extends Component {
render() {
const { component: Component, ...rest } = this.props //error: Property 'component' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.ts(2339)
const isAuth = getUser() //some function
return (
<Route
{...rest}
render={props =>
isAuth ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: '/login'
}}
/>
)
}
/>
)
}
}
export default withRouter(Auth) //error: Argument of type 'typeof Auth' is not assignable to parameter of type 'ComponentClass<RouteComponentProps<any, StaticContext, any>, any> | FunctionComponent<RouteComponentProps<any, StaticContext, any>> | (FunctionComponent<...> & ComponentClass<...>) | (ComponentClass<...> & FunctionComponent<...>)'.
但是Typescript会发出警告,我上面的代码有什么问题?