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

Conversation

vilchik-elena
Copy link
Contributor

Fixes #2658

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I left a minor suggestion. Also, I would rename the PR (and the ticket maybe) because it's more about fixing the detection of Promise.prototype.then() than allowing Pick<Promise> type.

Comment on lines 52 to 59
if (thenProperty && thenProperty.declarations && thenProperty.declarations?.length > 0) {
const declaration = thenProperty.declarations[0];
return (
declaration.kind === ts.SyntaxKind.MethodSignature ||
declaration.kind === ts.SyntaxKind.MethodDeclaration
);
}
return false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (thenProperty && thenProperty.declarations && thenProperty.declarations?.length > 0) {
const declaration = thenProperty.declarations[0];
return (
declaration.kind === ts.SyntaxKind.MethodSignature ||
declaration.kind === ts.SyntaxKind.MethodDeclaration
);
}
return false;
return thenProperty?.declarations?.some(
d => d.kind === ts.SyntaxKind.MethodSignature || d.kind === ts.SyntaxKind.MethodDeclaration,
);

@sonarsource-next
Copy link

@vilchik-elena vilchik-elena merged commit 651bb50 into master Aug 12, 2021
@vilchik-elena vilchik-elena deleted the issue-2658 branch August 12, 2021 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FP S4123 (no-invalid-await): TypeScript Pick type
3 participants