Skip to content

Files

Latest commit

 

History

History
39 lines (29 loc) · 984 Bytes

always-return.md

File metadata and controls

39 lines (29 loc) · 984 Bytes

Pattern: Missing return for then()

Issue: -

Description

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()
  }
})

Further Reading