小编jfb*_*m22的帖子

使用打字稿在Redux thunk中返回Promise

我收到此打字稿错误: Property 'then' does not exist on type 'ThunkAction<Promise<boolean>, IinitialState, undefined, any>'.

请帮忙!

我如何配置商店并包括以下类型:

    return createStore(
      rootReducer,
      intialState,
      require('redux-devtools-extension').composeWithDevTools(
        applyMiddleware(
          thunk as ThunkMiddleware<IinitialState, any>,
          require('redux-immutable-state-invariant').default()
        )
      )
Run Code Online (Sandbox Code Playgroud)

动作创建者:

type ThunkResult<R> = ThunkAction<R, IinitialState, undefined, any>;

export function anotherThunkAction(): ThunkResult<Promise<boolean>> {
  return (dispatch, getState) => {
    return Promise.resolve(true);
  }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的组件中,我有一个prop接口:

interface IProps {
  anotherThunkAction: typeof anotherThunkAction;
}
Run Code Online (Sandbox Code Playgroud)

然后:

  componentWillMount() {
    this.props.anotherThunkAction().then(() => {console.log('hello world')})
  }
Run Code Online (Sandbox Code Playgroud)

连接我正在使用react-i18next的位置:

export default translate('manageInventory')(
  connect(
    mapStateToProps,
    {
      anotherThunkAction
    }
  )(ManageInventory)
);
Run Code Online (Sandbox Code Playgroud)

typescript redux-thunk

6
推荐指数
1
解决办法
2233
查看次数

标签 统计

redux-thunk ×1

typescript ×1