将材料ui 1.x.x升级到3.x.x会导致withRouter中的打字稿不匹配

时间:2019-02-06 10:02:59

标签: reactjs typescript redux react-router material-ui

我正在尝试将Material UI版本升级到3.x.x,并且在使用withRouter函数时遇到以下类型不匹配的情况。相同的确切代码适用于任何1.x.x版本。

  

TS2345:类型'ComponentType&StyledComponentProps>的参数不能分配给类型'ComponentType>的参数。类型'ComponentClass&StyledComponentProps,ComponentState>'不可分配给'ComponentType>'类型。类型'ComponentClass&StyledComponentProps,ComponentState>'不能分配给'StatelessComponent>类型。属性类型“ propTypes”不兼容。类型'ValidationMap&StyledComponentProps>没有与类型'ValidationMap>'相同的属性。

代码:

import React from "react";
import { connect } from "react-redux";
import { Redirect, RouteComponentProps, withRouter } from "react-router";
import {createStyles, StyleRulesCallback, WithStyles} from "@material-ui/core/styles";
import {withStyles} from "@material-ui/core/styles/withStyles";

interface AppDataLoaderProps extends RouteComponentProps<{}> {...}

class AppDataLoader extends React.Component<AppDataLoaderProps & WithStyles, {}> {

...

}  

const styles: StyleRulesCallback = () => createStyles({...})

const mapStateToProps = (state: AppState, ownProps) => {...}
const mapDispatchToProps = (dispatch, ownProps) => {...}

const componentWithStyles = withStyles(styles)(AppDataLoader);
const componentWithRouter = withRouter(componentWithStyles);

export default connect(mapStateToProps, mapDispatchToProps(componentWithRouter);

0 个答案:

没有答案