-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Uncalled function checks only works with single conditional #42835
Conversation
611f5b3
to
e848beb
Compare
tests/baselines/reference/truthinessCallExpressionCoercion2.errors.txt
Outdated
Show resolved
Hide resolved
@typescript-bot user test this @jonhue A couple of things to do next:
|
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
src/compiler/checker.ts
Outdated
@@ -34550,6 +34550,9 @@ namespace ts { | |||
} | |||
|
|||
const location = isBinaryExpression(condExpr) ? condExpr.right : condExpr; | |||
if (isBinaryExpression(condExpr) && condExpr.operatorToken.kind === SyntaxKind.BarBarToken) { | |||
checkTestingKnownTruthyCallableOrAwaitableType(condExpr.left, type, body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think recursion is a good idea here, because binary expressions might be pretty long, and because the core of checkTestingKnownTruthyCallableOrAwaitableType
is not too complex.
I'd move the getSignatureOfType
check before location
's declaration, then put the rest of the function in a helper that's called in a loop, something like:
helper(condExpr, body)
while (isBinaryExpression(condExpr) && condExpr.operatorToken.kind === SyntaxKind.BarBarToken) {
condExpr = condExpr.left
helper(condExpr, body)
}
(although you might be able to write it more elegantly)
// error | ||
} | ||
|
||
if (isFoo || isBar) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for safety, can you add a test like x || y || z() || foo
?
Actually, looking at the whole call chain, I think |
@sandersn Thank you for your comments! You're right, we do need to check the type per |
I like the code as-is, but it checks a lot more than before. I want to see whether there are many new errors in the user tests: @typescript-bot user test this @jonhue can you take a look at those after they're done running? Edit: I'll sign off if you find that there aren't a lot of bogus errors appearing. |
@sandersn looks like something went wrong while running the tests. I can't really gather from the logs what exactly went wrong. Could you take a brief look/rerun the tests? 🙂 |
@typescript-bot user test this |
No report from typescript-bot again =( I manually checked the DT run and there weren't any new failures. It looks like the user test run failed to post a comment after it successfully pushed to the existing PR at https://github.com/typescript-bot/TypeScript/pull/158/files I looked at the existing PR and saw two new errors: the fluentui one is good. It looks like the author forgot that |
Since this is a new feature, I'll merge this after the 4.3 beta is done. |
The TypeScript team hasn't accepted the linked issue #35584. If you can get it accepted, this PR will have a better chance of being reviewed. |
Thank you all for your work in this 👍 Glad to see it added |
This pull request makes two changes:
||
binary expressions for uncalled functions (not just the rightmost ones)!
unary expressions for uncalled functions (if the function cannot beundefined
)Fixes #35584