Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用typescript在Redux thunk中返回承诺_Typescript_Redux Thunk - Fatal编程技术网

使用typescript在Redux thunk中返回承诺

使用typescript在Redux thunk中返回承诺,typescript,redux-thunk,Typescript,Redux Thunk,我收到此类型脚本错误:属性“then”在类型“ThunkAction”上不存在。 请帮忙 我如何配置我的存储并包括以下类型: return createStore( rootReducer, intialState, require('redux-devtools-extension').composeWithDevTools( applyMiddleware( thunk as ThunkMiddleware<

我收到此类型脚本错误:
属性“then”在类型“ThunkAction”上不存在。

请帮忙

我如何配置我的存储并包括以下类型:

    return createStore(
      rootReducer,
      intialState,
      require('redux-devtools-extension').composeWithDevTools(
        applyMiddleware(
          thunk as ThunkMiddleware<IinitialState, any>,
          require('redux-immutable-state-invariant').default()
        )
      )
然后:

  componentWillMount() {
    this.props.anotherThunkAction().then(() => {console.log('hello world')})
  }
连接我使用react-I18的位置下一步:

export default translate('manageInventory')(
  connect(
    mapStateToProps,
    {
      anotherThunkAction
    }
  )(ManageInventory)
);

我认为你没有把事情安排妥当。。。您正在调用您的操作,但未将其传递到商店

如果您直接调用该操作,您将返回:

ThunkAction<Promise<boolean>, IinitialState, undefined, any>

这将在
道具中添加另一个
动作
,您可以调用它,它将正确地调用您的动作并返回承诺。

谢谢@tswaters,这帮助我意识到我需要提供更多细节。我更新了我的问题。Sheesh布线时涉及到很多部件。如果我错了,请纠正我的错误,但我相信由于我正在applyMiddleware函数中添加类型,因此我不需要在所有mapDispatchToProps函数中添加该类型。@JFBlom22您是正确的。我也遇到了同样的问题,并试图找出最好的打字方式。我真的认为redux thunk和redux可能没有正确的打字。。。除了
mapDispatchToProps
功能外,我可以键入所有内容。有什么办法可以解决这个问题吗?const-mapDispatchToProps=(dispatch:ThunkDispatch)=>({dispatch:(arg:any)=>dispatch(dispatch(arg))})this.props.dispatch(createClient(this.state.name))。然后(client=>{this.props.history.push(
/clients/${client.payload.id}/code>);)
export default translate('manageInventory')(
  connect(
    mapStateToProps,
    {
      anotherThunkAction
    }
  )(ManageInventory)
);
ThunkAction<Promise<boolean>, IinitialState, undefined, any>
type MyThunkDispatch = ThunkDispatch<IinitialState, undefined, any>

const mapDispatchToProps = (dispatch: MyThunkDispatch) => ({
  anotherThunkAction: () => dispatch(anotherThunkAction())
})

connect(null, mapDispatchToProps)(MyComponent)