我是打字稿的新手,我一直在想分配哪种打字稿。现在我有东西,但是我该如何映射所有动作呢?
它是这样的:
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;
答案 0 :(得分:0)
尝试一下。
const dispatch: React.Dispatch<ProjectActionTypes | GeneralActionTypes>;
const mapDispatchToProps = (dispatch) => ({
generalActions: bindActionCreators(GeneralActions, dispatch)
});