Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

await-promise: correctly unwrap ReferenceTypes #3383

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.