Glavin001/tslint-clean-code

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

Open

#2 opened on 2017年8月18日

GitHub で見る
 (1 comment) (0 reactions) (1 assignee)TypeScript (15 forks)github user discovery
help wantedrule

Repository metrics

Stars
 (175 stars)
PR merge metrics
 (30d に merged PR はありません)

説明

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

コントリビューターガイド