Title: allow storing results of narrowing in booleans for further narrowing · Issue #24865 · microsoft/TypeScript · GitHub
Open Graph Title: allow storing results of narrowing in booleans for further narrowing · Issue #24865 · microsoft/TypeScript
X Title: allow storing results of narrowing in booleans for further narrowing · Issue #24865 · microsoft/TypeScript
Description: Search Terms https://github.com/Microsoft/TypeScript/search?q=type+guards+constants+narrowing&type=Issues Suggestion There is no way to use a saved result of a type guard evaluation for narrowing. Allow narrowing by storing assertions (b...
Open Graph Description: Search Terms https://github.com/Microsoft/TypeScript/search?q=type+guards+constants+narrowing&type=Issues Suggestion There is no way to use a saved result of a type guard evaluation for narrowing. ...
X Description: Search Terms https://github.com/Microsoft/TypeScript/search?q=type+guards+constants+narrowing&type=Issues Suggestion There is no way to use a saved result of a type guard evaluation for narrowi...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/24865
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"allow storing results of narrowing in booleans for further narrowing","articleBody":"## Search Terms\r\n\r\nhttps://github.com/Microsoft/TypeScript/search?q=type+guards+constants+narrowing&type=Issues\r\n\r\n## Suggestion\r\n\r\nThere is no way to use a saved result of a type guard evaluation for narrowing. Allow narrowing by\r\n- storing assertions (booleans) of narrowing into constants\r\n- impose narrowing based on the values carried by those constants\r\n\r\n## Use Cases\r\n\r\n- reuse for narrowing evaluations, in case there are two places that narrow using the same guard on the same value\r\n- declutter \"if\" expressions\r\n- give names to narrowing facts for better readability\r\n\r\n## Examples\r\n\r\n```ts\r\n// now\r\n if (\r\n isLoneAvailableCapacity(feed) &&\r\n (isAvailableCapacitySubbeamPath(link) || isAvailableCapacityConnectivityLegPath(link)) &&\r\n toAvailableCapacityKey(feed.availableCapacity) === link.availableCapacityKey\r\n ) {\r\n\r\n\r\n// could be\r\n const isAvailableCapacityPairdWithPath = isLoneAvailableCapacity(feed) &&\r\n (isAvailableCapacitySubbeamPath(link) || isAvailableCapacityConnectivityLegPath(link)) &&\r\n toAvailableCapacityKey(feed.availableCapacity) === link.availableCapacityKey\r\n\r\n if (isAvailableCapacityPairdWithPath) {\r\n }\r\n\r\n\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [+] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [+] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [+] This could be implemented without emitting different JS based on the types of the expressions\r\n* [+] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n","author":{"url":"https://github.com/zpdDG4gta8XKpMCd","@type":"Person","name":"zpdDG4gta8XKpMCd"},"datePublished":"2018-06-11T17:44:40Z","url":"https://github.com/microsoft/TypeScript/issues/24865"}
| 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:65b66470-1d10-3501-4d16-a7e8608416e2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC96:1C619:742485:A39D6A:6B047EE6 |
| html-safe-nonce | 0b23e0d05acd0bc174890d838b8d6bc3a445c1b639b59b9ee7a51ada0f3a2211 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzk2OjFDNjE5Ojc0MjQ4NTpBMzlENkE6NkIwNDdFRTYiLCJ2aXNpdG9yX2lkIjoiMjYyMzAyNjIwODM3OTc5NzIyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2c7f60160cf81fbb86ffcd084a7a605ba49b00aa955bef641b46697d15a58ea9 |
| hovercard-subject-tag | issue:331285234 |
| 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/24865/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c7c1444c4a6aaeed9331d540fe2fe3bb813caff26cc5c929e3d0e9965f2b5902/microsoft/TypeScript/issues/24865 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c7c1444c4a6aaeed9331d540fe2fe3bb813caff26cc5c929e3d0e9965f2b5902/microsoft/TypeScript/issues/24865 |
| og:image:alt | Search Terms https://github.com/Microsoft/TypeScript/search?q=type+guards+constants+narrowing&type=Issues Suggestion There is no way to use a saved result of a type guard evaluation for narrowing. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zpdDG4gta8XKpMCd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0366ddfb372682a32e92a5d86155cb08fa83e5bbe79953a968789f2f7e24c511 |
| 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 | ed3f2e01f6b7672780c586c8af0e72726374d7b6 |
| 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