Dealing with Promise executor functions ESLint error

Viewed 1080

The following block of code throws two warnings

  1. ESLint: Promise executor functions should not be async. (no-async-promise-executor)
  2. ESLint: Promise returned in function argument where a void return was expected. (@typescript-eslint/no-misused-promises)

What is the best way of rewriting it to get rid of the error messages?

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);
    }
  });
}
1 Answers
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
  });
}

No need to use promise at all, and you can throw an error.

Related