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 从另一个thunk中分派thunk,该thunk是使用redux toolkit中的CreateSynchThunk创建的_Typescript_Redux_Redux Toolkit - Fatal编程技术网

Typescript 从另一个thunk中分派thunk,该thunk是使用redux toolkit中的CreateSynchThunk创建的

Typescript 从另一个thunk中分派thunk,该thunk是使用redux toolkit中的CreateSynchThunk创建的,typescript,redux,redux-toolkit,Typescript,Redux,Redux Toolkit,这更像是一个typescript问题,但我的问题是@redux/toolkit中方法内部的特定问题。发送thunk操作的返回类型是什么 constmyservice=(num:number)=>Promise.resolve(num.toString()); const myAction=createAsyncThunk( “FOO”,我的服务 ) const myFirstAction=createAsyncThunk< 字符串,//返回类型 编号//参数类型 >('First',(num)=

这更像是一个typescript问题,但我的问题是
@redux/toolkit
中方法内部的特定问题。发送thunk操作的返回类型是什么

constmyservice=(num:number)=>Promise.resolve(num.toString());
const myAction=createAsyncThunk(
“FOO”,我的服务
)
const myFirstAction=createAsyncThunk<
字符串,//返回类型
编号//参数类型
>('First',(num)=>{
return myService(num)//直接调用服务OK
})
const mySecondAction=createAsyncThunk<
字符串,//有效,因为我正在对已解析的值调用unwrapResult
编号,//参数类型
{
调度:AppDispatch,
}
>('Second',(num,{dispatch})=>{
返回调度(myFirstAction(num))。然后(unwrapResult)
})
const myThirdAction=createAsynchThunk<
字符串,//失败??('Third',(num,{dispatch})=>{
退货派送(myFirstAction(num))
})

严格地说,它是

ReturnType< AsyncThunkActionCreator<Returned, ThunkArg, ThunkApiConfig> >
ReturnType
但是,由于该类型未导出

ReturnType< AsyncThunk<
  Returned,
  ThunkArg,
  ThunkApiConfig
> >
ReturnType >
我们应该做到这一点


您可以查看此类型的来源。

AppDispatch来自导出类型AppDispatch=typeof store。dispatchBTW再次感谢@phry的回答:)