Skip to content

Commit

Permalink
await-promise: correctly unwrap ReferenceTypes (palantir#3383)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff authored and adidahiya committed Oct 23, 2017
1 parent b0da1b0 commit f810a5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/rules/awaitPromiseRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ function walk(ctx: Lint.WalkContext<Set<string>>, tc: ts.TypeChecker) {
}

function containsType(type: ts.Type, predicate: (name: string) => boolean): boolean {
if (Lint.isTypeFlagSet(type, ts.TypeFlags.Any) ||
isTypeReference(type) && type.target.symbol !== undefined && predicate(type.target.symbol.name)) {
if (Lint.isTypeFlagSet(type, ts.TypeFlags.Any)) {
return true;
}
if (isTypeReference(type)) {
type = type.target;
}
if (type.symbol !== undefined && predicate(type.symbol.name)) {
return true;
}
if (isUnionOrIntersectionType(type)) {
return type.types.some((t) => containsType(t, predicate));
}

const bases = type.getBaseTypes();
return bases !== undefined && bases.some((t) => containsType(t, predicate));
}
Expand Down
7 changes: 7 additions & 0 deletions test/rules/await-promise/es6-promise/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ async function fPromise() {
await intersectionPromise;
}

type AxiosResponse<T> = T;
interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {}

async function extendsPromise(v: AxiosPromise<any>) {
await v;
}

[0]: Invalid 'await' of a non-Promise value.

0 comments on commit f810a5a

Please sign in to comment.