Pattern: Missing return for then()
Issue: -
Ensure that inside a then()
you make sure to return
a new promise or value.
This rule also allows to throw
inside a then()
which is essentially the same as return Promise.reject()
.
Example of correct code:
myPromise.then((val) => val * 2));
myPromise.then(function(val) { return val * 2; });
myPromise.then(doSomething); // could be either
myPromise.then((b) => { if (b) { return "yes" } else { return "no" } });
Example of incorrect code:
myPromise.then(function(val) {})
myPromise.then(() => {
doSomething()
})
myPromise.then(b => {
if (b) {
return 'yes'
} else {
forgotToReturn()
}
})