Skip to content

Instantly share code, notes, and snippets.

@gnowland
Last active December 16, 2021 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnowland/7eb83fc751cb7af793a525687ba0815d to your computer and use it in GitHub Desktop.
Save gnowland/7eb83fc751cb7af793a525687ba0815d to your computer and use it in GitHub Desktop.

Promises must be handled appropriately or explicitly marked as ignored with the void operator.eslint@typescript-eslint/no-floating-promises

That's a crappy error message. A better one might be,

every expression of type Promise must end with a call to .catch or a call to .then with a rejection handler (source).

So, for example, if you do

PromiseFunction()
  .catch(err => handle(err))
  .then(() => console.log('this will succeed'))

then you will still have a tslint problem, because the type of .then(...) is a promise, and it has to end with a catch. The fix would be appending a .catch clause, for example,

PromiseFunction()
  .catch(err => handle(err))
  .then(() => console.log('this will succeed'))
  .catch(() => 'obligatory catch')

or just disabling tslint for that line via:

PromiseFunction()
  .catch(err => handle(err))
  // tslint:disable-next-line:no-unsafe-any
  .then(() => console.log('this will succeed'))

Alternatively, you could reverse the order of the .then and .catch statements. However, that stops the .then from executing if an error does occur, which you presumably want if you encountered this problem.


From: https://stackoverflow.com/questions/43980188/what-could-this-be-about-tslint-error-promises-must-be-handled-appropriately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment