typescript - 处理 Promise 执行器函数 ESLint 错误

标签 typescript eslint

下面的代码块抛出两个警告

  1. ESLint:Promise 执行器函数不应该是异步的。 (无异步 promise 执行器)
  2. ESLint:Promise 在函数参数中返回,其中预期返回 void。 (@typescript-eslint/no-misused-promises)

重写它以消除错误消息的最佳方法是什么?

async signIn(email: string, password: string, redirectTo: string): Promise<unknown> {
  return new Promise(async (resolve, reject) => {
    const { error, data } = await this.supabaseClient.auth.signIn(
      { email: email, password: password },
      { redirectTo: redirectTo }
    );
    if (error) {
      reject(error);
    } else {
      resolve(data);
    }
  });
}

最佳答案

async signIn(email: string, password: string, redirectTo: string) {
    const { error, data } = await this.supabaseClient.auth.signIn(
      { email: email, password: password },
      { redirectTo: redirectTo }
    );
    if (error) {
      throw new Error(error);
    }

    return data
  });
}

根本不用promise,抛出错误即可。

关于typescript - 处理 Promise 执行器函数 ESLint 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68656930/

相关文章:

javascript - 如何使用 eslint 验证 VSCode 中的 Adob​​e Extendscript (.jsx) 文件

javascript - 通过调用自定义函数将 var 转换为子字符串来替换字符串 - Algo JS

javascript - bool 检查在 NodeJS 中不起作用

javascript - 如何设置字符串的智能感知以避免使用 VS 代码在 JavaScript 中键入无效值

javascript - Object.hasOwnProperty() 产生 ESLint 'no-prototype-builtins' 错误 : how to fix?

reactjs - Reactjs 中的 EsLint "react/jsx-props-no-spreading"错误禁用

typescript - 类型别名循环引用自身

javascript - typescript :使用外部声明的变量

javascript - 子组件在 Angular 4 中不起作用

ecmascript-6 - Eslint-分配的胖箭头/属性初始化程序的 `Parsing error: unexpected token =`错误