Use an asynchronous IIFE inside the callback

  angular, eslint, javascript, typescript

How do I use an asynchronous IIFE inside the callback as per this example here to avoid the error message: Promise returned in function argument where a void return was expected.

  signIn(email: string, password: string, course?: ICourse): Promise<void> {
    return new Promise<UserCredential>((resolve, reject) =>
      this.afAuth.signInWithEmailAndPassword(email, password).then(
        (res) => {
          resolve(res);
        },
        (error: { message: string }) => {
          reject(error);
          this.toastrService.warning('Something has gone wrong. Please try again.', 'Oops!');
          this.logger.debug('An error occurred during Email Sign In');
          this.logger.error(error.message);
        }
      )
    ).then(
      (result: UserCredential) => {
        if (course && result.user) {
          this.builderSignIn(course, result.user.uid);
        } else {
          if (result != null) {
            this.ngZone.run(() => {
              void this.router.navigate(['dashboard']);
            });
          }
        }
      },
      (error: { message: string }) => {
        this.toastrService.warning(error.message, 'Oops!');
      }
    );
  }

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.