【发布时间】:2018-03-13 01:37:33
【问题描述】:
我正在尝试定义一个承诺的类型。 以下是部分代码或者如果你想在github上查找它:https://github.com/Electra-project/Electra-Desktop/blob/master/src/app/header/epics.ts
export function getStakingInfo(action$: ActionsObservable<HeaderActions>, store: any): any {
return action$.ofType(ActionNames.GET_STAKING_INFO)
.map(() => store.getState().electra.electraJs) // get electraJs object from the store
.filter((electraJs: any) => electraJs) // check if electraJs exists
.map(async (electraJs: any) => electraJs.wallet.getStakingInfo())
.switchMap(async (promise: Promise<WalletStakingInfo>) => new Promise((resolve) => {
promise
.then((data: WalletStakingInfo) => {
resolve({
payload: {
...data
},
type: ActionNames.GET_STAKING_INFO_SUCCESS
})
})
.catch((err: any) => {
resolve({
type: ActionNames.GET_STAKING_INFO_FAIL
})
})
}))
.catch((err: any) =>
Observable.of({
type: ActionNames.GET_STAKING_INFO_FAIL
}))
}
我收到一条错误消息,指出上述代码部分中的resolve 不是类型定义的new Promise((resolve) => {。但是我不确定解决的类型。
任何人都可以指导我这里应该使用什么类型的解决方案?
【问题讨论】:
标签: reactjs typescript redux redux-observable