Title: Breaking change: Use of 'void' in control flow constructs is now disallowed · Issue #26262 · microsoft/TypeScript · GitHub
Open Graph Title: Breaking change: Use of 'void' in control flow constructs is now disallowed · Issue #26262 · microsoft/TypeScript
X Title: Breaking change: Use of 'void' in control flow constructs is now disallowed · Issue #26262 · microsoft/TypeScript
Description: TypeScript Version: 3.1 Search Terms: boolean void truthy falsy if while do for not An expression of type 'void' cannot be tested for truthiness Code Consider this code: function existsAndIsCool(fileName: string) { fs.exists(fileName, ex...
Open Graph Description: TypeScript Version: 3.1 Search Terms: boolean void truthy falsy if while do for not An expression of type 'void' cannot be tested for truthiness Code Consider this code: function existsAndIsCool(fi...
X Description: TypeScript Version: 3.1 Search Terms: boolean void truthy falsy if while do for not An expression of type 'void' cannot be tested for truthiness Code Consider this code: function existsAndI...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26262
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Breaking change: Use of 'void' in control flow constructs is now disallowed","articleBody":"**TypeScript Version:** 3.1\r\n\r\n**Search Terms:** boolean void truthy falsy if while do for not\r\n\r\nAn expression of type 'void' cannot be tested for truthiness\r\n\r\n**Code**\r\n\r\nConsider this code:\r\n```ts\r\nfunction existsAndIsCool(fileName: string) {\r\n fs.exists(fileName, exists => {\r\n return exists && isCool(fileName);\r\n });\r\n}\r\n\r\nif (existsAndIsCool(\"myFile\")) {\r\n console.log(\"Cool!\");\r\n} else {\r\n console.log(\"Not cool :(\");\r\n}\r\n```\r\n\r\n**Expected behavior:** The \"Cool!\" branch is actually unreachable because `existsAndIsCool` returns `void`, not `boolean`. I should have been warned about this at some point.\r\n\r\n**Actual behavior:** No error, never cool 😢 \r\n\r\n**Playground Link:** [Link](http://www.typescriptlang.org/play/#src=declare%20const%20fs%3A%20%7B%20exists%3A%20(fileName%3A%20string%2C%20cb%3A%20(exists%3A%20boolean)%20%3D%3E%20void)%20%3D%3E%20void%3B%20%7D%0D%0Adeclare%20function%20isCool(fileName%3A%20string)%3A%20boolean%3B%0D%0A%0D%0Afunction%20existsAndIsCool(fileName%3A%20string)%20%7B%0D%0A%20%20fs.exists(fileName%2C%20exists%20%3D%3E%20%7B%0D%0A%20%20%20%20return%20exists%20%26%26%20isCool(fileName)%3B%0D%0A%20%20%7D)%3B%0D%0A%7D%0D%0A%0D%0Aif%20(existsAndIsCool(%22myFile%22))%20%7B%0D%0A%20%20console.log(%22Cool!%22)%3B%0D%0A%7D%20else%20%7B%0D%0A%20%20console.log(%22Not%20cool%20%3A(%22)%3B%0D%0A%7D))\r\n\r\n**Related Issues:** \r\nPR #26234 \r\n#7256\r\n#10942\r\n#7306\r\n","author":{"url":"https://github.com/RyanCavanaugh","@type":"Person","name":"RyanCavanaugh"},"datePublished":"2018-08-07T15:47:13Z","url":"https://github.com/microsoft/TypeScript/issues/26262"}
| 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:612a5b57-5a9e-c304-a798-1fd34781af22 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA56:26BC2B:50EC0C:71EC50:6B0445C0 |
| html-safe-nonce | ccf43fd2024c3dbbdae0f47d0497cd42115f27193fa847c9de7fd854571640b6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTU2OjI2QkMyQjo1MEVDMEM6NzFFQzUwOjZCMDQ0NUMwIiwidmlzaXRvcl9pZCI6IjMyNTM0MTU0MjkwNDUyNDEyODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 845ede25933af885e3c9d5b259013a5e31d35db2395d20f0e58a60a19dbc974f |
| hovercard-subject-tag | issue:348380741 |
| 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/26262/issue_layout |
| twitter:image | https://opengraph.githubassets.com/64f69d5f7ee0826ad7014158165fb7775bd6660b8151406d4273f2b8b2a05086/microsoft/TypeScript/issues/26262 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/64f69d5f7ee0826ad7014158165fb7775bd6660b8151406d4273f2b8b2a05086/microsoft/TypeScript/issues/26262 |
| og:image:alt | TypeScript Version: 3.1 Search Terms: boolean void truthy falsy if while do for not An expression of type 'void' cannot be tested for truthiness Code Consider this code: function existsAndIsCool(fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RyanCavanaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | d4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46 |
| 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 | 9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width