【发布时间】:2020-03-29 18:40:09
【问题描述】:
我有一个使用 JHipster 6.x 和 React JS 作为 UI 生成的应用程序。在许多屏幕中,我使用诸如
之类的 redux 方法获取数据方法:
export const getStudentsByCriteria: ICrudSearchAction<IStudent> = (query, page, size, sort) => ({
type: ACTION_TYPES.SEARCH_STUDENTS,
payload: axios.get<IStudent>(`${apiUrl}?${query}${sort ? `&page=${page}&size=${size}&sort=${sort}` : ''}`)
});
呼叫:
(this.props.getStudentsByCriteria('classSectionId.equals=' + classSectionId, 0, 50, "firstName,asc") as IPayload<IStudent>).payload.then((response) => { ... }
它一直工作得很好,但突然间我开始收到错误:TS2339: 类型 'IPayload | 上不存在属性'then' ((调度:任何)=> IPayload)'。 类型“IPayload”上不存在属性“then”
简单地调用 .then 会在 MS Code 中产生编译错误,但在本地运行没有任何问题,但是由于编译错误而不允许构建战争
(this.props.getStudentsByCriteria('classSectionId.equals=' + classSectionId, 0, 50, "firstName,asc").then((response) => { ... }
这应该返回 IPayload 并且 IPayload.payload.then ... 必须工作。它一直在工作,它突然停止工作很奇怪。
【问题讨论】:
-
也许你之前有一个
await? -
我没有。我没有更改代码中的任何内容。是的,项目中添加了一些组件