0

我是打字稿的新手,我一直想知道要发送哪种类型。现在我有,但我怎么能把所有的动作都映射到它呢?

这是它的样子:

interface PropTypes {
  title: string;
  generalActions: any;
}

const mapDispatchToProps = (dispatch: any) => ({
  generalActions: bindActionCreators(GeneralActions, dispatch)
});

我的类型文件:

export const ADD_PROJECT = "ADD_PROJECT";
export const DELETE_PROJECT = "DELETE_PROJECT";
export const CHANGE_TITLE = "CHANGE_TITLE";

export interface Project {
  title: string;
  subtitle: string;
}

export interface ChangeTitleAction {
  type: typeof CHANGE_TITLE;
  title: string;
}
// STATE
export interface ProjectsState {
  projects: Project[];
}

export interface GeneralState {
  title: string;
}

export type GeneralActionTypes = ChangeTitleAction;

export type ProjectActionTypes = AddProjectAction | DeleteProjectAction;
4

1 回答 1

0

尝试这个。

const dispatch: React.Dispatch<ProjectActionTypes | GeneralActionTypes>;

const mapDispatchToProps = (dispatch) => ({
  generalActions: bindActionCreators(GeneralActions, dispatch)
});

于 2020-02-22T16:00:04.533 回答