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 (and actually use) "always truthy promise" error #43023

Merged
merged 2 commits into from Mar 29, 2021

Conversation

DanielRosenwasser
Copy link
Member

Addresses some of the concerns in #43004 (comment)

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 1, 2021
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

tests/cases/compiler/truthinessCallExpressionCoercion.ts(66,13): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(76,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead?
Copy link
Contributor

Choose a reason for hiding this comment

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

👋 I think I first introduced this error message back when I contributed the first uncalled function check. I admit I didn't give it in-depth thought and it's kind of bothered me since. Since it's being adjusted, can I suggest one additional tweak?

Suggested change
tests/cases/compiler/truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always evaluate to true since this function appears to always be defined. Did you mean to call it instead?

Rationale being that return is a function-level concern, but these are almost always expressions.

Copy link
Member Author

Choose a reason for hiding this comment

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

That also kind of bugged me - what about "This condition will always be true"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Even better!

Copy link
Member

Choose a reason for hiding this comment

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

I don't like swapping "appears to always be" with "is". The wiggle room that the words give you isn't worth the extra reading, and the associated drop in number of people who will read to the end.

Just giving an incorrect error, regardless of wording, drops the compiler's credibility to zero, so you might as well be confident and clear in your wording.

Copy link
Member Author

Choose a reason for hiding this comment

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

@sandersn we keep getting very annoying discussions about "will always be true because the types have no overlap", often because of issues like #9998.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Looks good, except back out the "appears to" addition.

tests/cases/compiler/truthinessCallExpressionCoercion.ts(66,13): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(76,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(82,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
tests/cases/compiler/truthinessCallExpressionCoercion.ts(2,9): error TS2774: This condition will always return true since this function appears to always be defined. Did you mean to call it instead?
Copy link
Member

Choose a reason for hiding this comment

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

I don't like swapping "appears to always be" with "is". The wiggle room that the words give you isn't worth the extra reading, and the associated drop in number of people who will read to the end.

Just giving an incorrect error, regardless of wording, drops the compiler's credibility to zero, so you might as well be confident and clear in your wording.

@sandersn sandersn added this to Not started in PR Backlog Mar 16, 2021
@sandersn sandersn moved this from Not started to Waiting on author in PR Backlog Mar 19, 2021
@DanielRosenwasser DanielRosenwasser merged commit a3d207a into master Mar 29, 2021
PR Backlog automation moved this from Waiting on author to Done Mar 29, 2021
@DanielRosenwasser DanielRosenwasser deleted the fixUpErrorsOnAlwaysTrue branch March 29, 2021 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants