Glavin001/tslint-clean-code

no-return-promise-mixed-type: Do not allow functions to return promises mixed with something non-promise

Open

#2 aperta il 18 ago 2017

Vedi su GitHub
 (1 commento) (0 reazioni) (1 assegnatario)TypeScript (15 fork)github user discovery
help wantedrule

Metriche repository

Star
 (175 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Bad

function doStuff(input) {
  if (input === "stuff") {
    return Promise.resolve(true);
  }
  return false;
}

Consider the following:

doStuff("stuff")
  .then(result => console.log(result)); // => true

doStuff("other") // *****Cannot call .then on false!*******
  .then(result => console.log(result));

It should always return a Promise!

Good

function doStuff(input) {
  if (input === "doIt") {
    return Promise.resolve(true);
  }
  return Promise.resolve(false);
}

Guida contributor