-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Confusing error message: Operator '===' cannot be applied to types '1' and '0'. #25245
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
Comments
We should have a sub-elaboration when both operands are literal types (or unions of literal types) that says something like
and is
in the general case |
@DanielRosenwasser let's workshop it for a few hours 🎈 |
The new error is misleading. You can't compare unrelated interfaces, but it's still possible and reasonable that one object could implement both of them: const a = { x: 0, y: 0 };
const b: { x: number } = a;
const c: { y: number } = a;
console.log(b == c); but now it claims that "The types of these values indicate that this condition will always be 'false'." |
@DanielRosenwasser - @jeffreymorlan makes a good point here, I was expecting that we'd implement the "when both operands are literal types (or unions of literal types)" constraint for this message. |
great, saved my time |
The current error message is:
Still a bit confusing if you aren't used to literal types and where |
TypeScript Version: 3.0.0-dev.20180623
Search Terms:
Code
Bug:
The error message is:
Operator '===' cannot be applied to types '1' and '0'.
I found this error very confusing. It took me a while to understand that the error meant that the type on the left hand side was
1
.In this case, I think we should instead report that the condition always evaluates to false.
Related Issues:
/cc @chrisdias
The text was updated successfully, but these errors were encountered: