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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…