diff --git a/src/rules/awaitPromiseRule.ts b/src/rules/awaitPromiseRule.ts index 1cc245c62b6..4bf3f0c1fec 100644 --- a/src/rules/awaitPromiseRule.ts +++ b/src/rules/awaitPromiseRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { isAwaitExpression } from "tsutils"; +import { isAwaitExpression, isUnionOrIntersectionType } from "tsutils"; import * as ts from "typescript"; import * as Lint from "../index"; @@ -65,7 +65,7 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker, promiseTypes: Set return true; } - if (isUnionType(type)) { + if (isUnionOrIntersectionType(type)) { return type.types.some(couldBePromise); } @@ -78,7 +78,3 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker, promiseTypes: Set return target !== undefined && target.symbol !== undefined && promiseTypes.has(target.symbol.name); } } - -function isUnionType(type: ts.Type): type is ts.UnionType { - return Lint.isTypeFlagSet(type, ts.TypeFlags.Union); -} diff --git a/test/rules/await-promise/custom-promise/test.ts.lint b/test/rules/await-promise/custom-promise/test.ts.lint index 1b89af2d1b0..5d8221fdc7f 100644 --- a/test/rules/await-promise/custom-promise/test.ts.lint +++ b/test/rules/await-promise/custom-promise/test.ts.lint @@ -44,6 +44,10 @@ async function fStandardPromise() { await (Math.random() > 0.5 ? numberPromise : 0); await (Math.random() > 0.5 ? foo : 0); await (Math.random() > 0.5 ? bar : 0); + + // intersection type + const intersectionPromise: Promise & number; + await intersectionPromise; } async function fCustomPromise() { @@ -65,6 +69,10 @@ async function fCustomPromise() { await (Math.random() > 0.5 ? numberPromise : 0); await (Math.random() > 0.5 ? foo : 0); await (Math.random() > 0.5 ? bar : 0); + + // intersection type + const intersectionPromise: CustomPromise & number; + await intersectionPromise; } [0]: 'await' of non-Promise. diff --git a/test/rules/await-promise/es6-promise/test.ts.lint b/test/rules/await-promise/es6-promise/test.ts.lint index b049ec8c3c3..2d8ed107a56 100644 --- a/test/rules/await-promise/es6-promise/test.ts.lint +++ b/test/rules/await-promise/es6-promise/test.ts.lint @@ -42,6 +42,10 @@ async function fPromise() { await (Math.random() > 0.5 ? numberPromise : 0); await (Math.random() > 0.5 ? foo : 0); await (Math.random() > 0.5 ? bar : 0); + + // intersection type + const intersectionPromise: Promise & number; + await intersectionPromise; } [0]: 'await' of non-Promise.