简体   繁体   中英

Typescript error after update of react and react-dom

I have upgraded react and react-dom (and also @type/react and @types/react-dom) to the latest version to use react hooks. But now I am getting this type error:

Argument of type typeof is not assignable to parameter of type 'ComponentType< Props & RouteComponentProps<{}, StaticContext, any>>

interface LoginProps {}

class Login extends React.PureComponent<LoginProps & RouteComponentProps, {}> {

}

export default withRouter(Login);

I suspect the type definitions to be the issue, but I cannot find out what.

I think the problem is with the way you have tried to extend your interface.

In typescript interfaces can be extended using the extends keyword (ie interfaceA extends interfaceB ) while types can be extended using the method you have used (ie typeA & typeB ).

And since your LoginProps is an interface, your code is breaking.

try rewriting your code as

interface LoginProps extends RouteComponentProps {}

class Login extends React.PureComponent<LoginProps, {}> {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM