CNode

redux-saga 在用 typescript 开发时 call 的返回值类型怎么确定?

问答
DDiamondYuan发布于7 年前最后回复7 年前0 回复3768 浏览0 收藏

相关 issue https://github.com/Microsoft/TypeScript/issues/2873

我目前的解决方法是手动给返回结果标注类型。

interface TypedCommonStorageInterface {
  /** --------图床--------- */

  addImageHosting(imageHosting: ImageHosting): Promise<ImageHosting[]>;

  getImageHosting(): Promise<ImageHosting[]>;
}


type PromiseType<T extends Promise<any>> = T extends Promise<infer U>
  ? U
  : never;

   const imageHostingList: PromiseType<
      ReturnType<typeof storage.addImageHosting>
    > = yield call(storage.addImageHosting, imageHosting);
查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。
参与回复
登录后即可参与回复。登录