Title: Treat `Boolean(x)` equally as double not `!!x` · Issue #37180 · microsoft/TypeScript · GitHub
Open Graph Title: Treat `Boolean(x)` equally as double not `!!x` · Issue #37180 · microsoft/TypeScript
X Title: Treat `Boolean(x)` equally as double not `!!x` · Issue #37180 · microsoft/TypeScript
Description: In complex boolean expressions it's clearer to do Boolean(x) cast rather than !!x in favor of readability. Also the latter way of casting something to boolean is error prone and it's easy to mistype !. Typescript should treat Boolean(x) ...
Open Graph Description: In complex boolean expressions it's clearer to do Boolean(x) cast rather than !!x in favor of readability. Also the latter way of casting something to boolean is error prone and it's easy to mistyp...
X Description: In complex boolean expressions it's clearer to do Boolean(x) cast rather than !!x in favor of readability. Also the latter way of casting something to boolean is error prone and it's easy t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/37180
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Treat `Boolean(x)` equally as double not `!!x`","articleBody":"In complex boolean expressions it's clearer to do `Boolean(x)` cast rather than `!!x` in favor of readability. Also the latter way of casting something to boolean is error prone and it's easy to mistype `!`. Typescript should treat `Boolean(x)` the same way as `!!`.\r\n\r\n\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:** 3.6.3,3.7.5,3.8.3 (tried top 3 available in playground)\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\n\r\nboolean cast non null \r\ndouble negation boolean cast\r\ndouble not Boolean \r\n\r\n**Code**\r\n\r\n```ts\r\ninterface A {\r\n a: number\r\n}\r\n\r\nconst a: A | undefined\r\n\r\nconsole.log(a && a?.a) // works\r\nconsole.log(!!a && a.a) // works\r\nconsole.log(Boolean(a) && a.a) // warns that `Object is possibly 'undefined'.(2532)`\r\n```\r\n\r\n**Expected behavior:**\r\n`Boolean(x)` should be treated as equivalent of `!!x`\r\n\r\n\r\n**Actual behavior:**\r\nUsing `Boolean` as a function does not contribute to TS understanding of object existense\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=9&pc=31#code/JYOwLgpgTgZghgYwgAgILIN4Chm+XALmRAFcBbAI2iwF8ssEB7EAZzHyPQB9kSQATCDFAR+9Jq0YAbCADopjAOYAKOMgBk6-AH5ZcAJQNmLaXIUqAhBbWb8ewxJMz5S5QCFGpuCFX6NWuHsgA\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/maxkomarychev","@type":"Person","name":"maxkomarychev"},"datePublished":"2020-03-03T06:14:47Z","url":"https://github.com/microsoft/TypeScript/issues/37180"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1b020c28-b1f6-1ba3-54b8-3dd8d0b4460c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A89A:95C88:A94122:E1E2F8:6B00EAA2 |
| html-safe-nonce | f7cfed22a772268936d839e2ae58b654c9cf47a5f9e26e39330e9e41757417ce |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODlBOjk1Qzg4OkE5NDEyMjpFMUUyRjg6NkIwMEVBQTIiLCJ2aXNpdG9yX2lkIjoiMzAyMzA4MTU0NzA1MDgzODY5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6e52aa9c2632e9a9cc8e0ae13b45b21fbac6431dafe17bac0e1cf0c83925973e |
| hovercard-subject-tag | issue:574440994 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/37180/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f6c74fa4d18542a9ca4e10d08f07c83088b335c0b5767c4ae24c9099f68a1504/microsoft/TypeScript/issues/37180 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f6c74fa4d18542a9ca4e10d08f07c83088b335c0b5767c4ae24c9099f68a1504/microsoft/TypeScript/issues/37180 |
| og:image:alt | In complex boolean expressions it's clearer to do Boolean(x) cast rather than !!x in favor of readability. Also the latter way of casting something to boolean is error prone and it's easy to mistyp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maxkomarychev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width