Glavin001/tslint-clean-code

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

Open

#2 geöffnet am 18. Aug. 2017

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (1 zugewiesene Person)TypeScript (15 Forks)github user discovery
help wantedrule

Repository-Metriken

Stars
 (175 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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

Contributor Guide