无法确定如何在同一组件上使用Redux和React-router

Kor*_*exx 6 typescript reactjs react-router-redux

我开始学习打字稿,这是一种我不理解的行为.

我收到了这个错误:

Type 'ComponentClass<{}>' is not assignable to type 'StatelessComponent<void | RouteComponentProps<any>> | ComponentClass<void | RouteComponentProps<a...'.
  Type 'ComponentClass<{}>' is not assignable to type 'ComponentClass<void | RouteComponentProps<any>>'.
    Type '{}' is not assignable to type 'void | RouteComponentProps<any>'.
      Type '{}' is not assignable to type 'RouteComponentProps<any>'.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这是我的App组件:

interface AppProps extends React.Props<void> {
  todos: TodoItemData[];
  actions: typeof TodoActions;
};

interface AppState {
  /* empty */
}

class App extends React.Component<AppProps, AppState>{
  render() {return (<div></div>);
  }
}

function mapStateToProps(state: RootState) {
  return {
    todos: state.todos
  };
}

function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(TodoActions as any, dispatch)
  };
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(App);
Run Code Online (Sandbox Code Playgroud)

如果我通过void或React.Props更改我的App组件AppProps的声明我没有错误,但我总是有一个AppProps.

我不会理解为什么它不起作用,AppProps正在从React.Props扩展.你看错了吗?

Izh*_*aki 0

根据GitHub 上的这个答案,这可能有效:

export default connect< AppProps, {}, {} >(
  mapStateToProps,
  mapDispatchToProps
)(App);
Run Code Online (Sandbox Code Playgroud)