Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve S4123 (no-invalid-await): allow Pick<Promise> type #2755

Merged
merged 4 commits into from
Aug 12, 2021
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
4 changes: 3 additions & 1 deletion eslint-bridge/src/rules/no-invalid-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export const rule: Rule.RuleModule = {

function hasThenMethod(type: ts.Type) {
const thenProperty = type.getProperty('then');
return Boolean(thenProperty && thenProperty.flags & ts.SymbolFlags.Method);
return thenProperty?.declarations?.some(
d => d.kind === ts.SyntaxKind.MethodSignature || d.kind === ts.SyntaxKind.MethodDeclaration,
);
}

function isAny(type: ts.Type) {
Expand Down
11 changes: 11 additions & 0 deletions eslint-bridge/tests/rules/no-invalid-await.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ ruleTester.run('await should only be used with promises.', rule, {
}
`,
},
{
code: `
interface MyQuery<T> extends Pick<Promise<T>, keyof Promise<T>> {
toQuery(): string;
}
async function foo(query: MyQuery<string>) {
const result = await query;
console.log(result);
}
`,
},
],
invalid: [
{
Expand Down