【发布时间】:2020-09-12 02:31:30
【问题描述】:
我有一个类型
export type AppThunk<ReturnType> = ThunkAction<
ReturnType,
RootState,
unknown,
Action<string>
>;
现在如果我像下面这样使用它
export const loadCourse = (id: string): AppThunk => {
return (dispatch: Dispatch) => {
dispatch(loadCourseSuccess(undefined));
return api
.getCourse(id)
.then((course) => dispatch(loadCourseSuccess(course)));
};
};
typescript 编译器报错,告诉我在 AppThunk 中提供泛型参数,如何让它自动推断泛型返回类型参数?
【问题讨论】:
标签: reactjs typescript redux