redux-saga 在用 typescript 开发时 call 的返回值类型怎么确定?
发布于 5 年前 作者 DiamondYuan 3026 次浏览 来自 问答

相关 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);
回到顶部