Skip to content

Commit

Permalink
await-promise: Fix - consider Promises in union types too (palantir#2661
Browse files Browse the repository at this point in the history
)
  • Loading branch information
darxriggs committed May 7, 2017
1 parent 3f714cf commit 18f4268
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/awaitPromiseRule.ts
Expand Up @@ -57,7 +57,7 @@ function walk(ctx: Lint.WalkContext<void>, tc: ts.TypeChecker) {
}

if (isUnionType(type)) {
return type.types.some(isPromiseType);
return type.types.some(couldBePromise);
}

const bases = type.getBaseTypes();
Expand Down
7 changes: 6 additions & 1 deletion test/rules/await-promise/test.ts.lint
Expand Up @@ -3,20 +3,25 @@ declare const isAny: any;

async function f() {
await isAny;
await (Math.random() > 0.5 ? isAny : 0);

await num;
await (Math.random() > 0.5 ? num : 0);

await 0;
~~~~~~~ [0]
await (Math.random() > 0.5 ? num : 0);
await (Math.random() > 0.5 ? "" : 0);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]

class MyPromise extends Promise<number> {}
const myPromise: MyPromise = MyPromise.resolve(2);
await myPromise;
await (Math.random() > 0.5 ? myPromise : 0);

class Foo extends MyPromise {}
const foo: Foo = Foo.resolve(2);
await foo;
await (Math.random() > 0.5 ? foo : 0);

class Bar extends Array {}
await new Bar();
Expand Down

0 comments on commit 18f4268

Please sign in to comment.