-
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
No TS2367 error when using unary not #55702
Comments
The only way those are "logically the same behavior" is because we know that since |
They are not identical in a general case but their result is identical in this case, as typescript knows the types. And this is the basis of TS2367 too - it only works/reports an error because it is aware of the types. This logic should also extend to ! and === false. |
This is just trading one inconsistency for another. We always allow if (x) { since const arr: object[] = /* some array */;
const x = arr[3];
if (x) { // truthy according to type system so it'd be inconsistent to allow if (x) {
} else { // <- !x must be true
} but not if (x) { |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
TS2367 unary not
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/FAMwrgdgxgLglgewgAhgRgDxSQZxsgFQD4AKZAQwCcBzALkIEp6DkBTADxlYgBMdkIYALYAjVpWQB+ZAG9y9PJTgRqAX2T0Q5ADY5Ws4AEhKrGGEooA5JYDcwVcGDYIeZO2QBeVGjJoArMgMdnAgyGQAhO4MssgA9LHIAO4AFgCeAghslJQIEsnirJJGzq7pXux2DsAhYW6eHl5auvrRMsW4+GVulcBAA
π» Code
π Actual behavior
Only error for line 11, even though line 7 should give an error too, since it's logically the same behavior.
π Expected behavior
Error for line 11 and line 7 since it's logically the same behavior.
Additional information about the issue
Vaguely the opposite of #44366
This issue is annoying, because of #44366 - since in some cases it only works with false and in some with unary not.
The text was updated successfully, but these errors were encountered: