Glavin001/tslint-clean-code

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

Open

#2 创建于 2017年8月18日

在 GitHub 查看
 (1 评论) (0 反应) (1 负责人)TypeScript (15 fork)github user discovery
help wantedrule

仓库指标

Star
 (175 star)
PR 合并指标
 (30 天内没有已合并 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);
}

贡献者指南