Title: Control flow analysis for destructured rest element of discriminated union · Issue #46680 · microsoft/TypeScript · GitHub
Open Graph Title: Control flow analysis for destructured rest element of discriminated union · Issue #46680 · microsoft/TypeScript
X Title: Control flow analysis for destructured rest element of discriminated union · Issue #46680 · microsoft/TypeScript
Description: Suggestion 🔍 Search Terms rest spread element destructure destructuring discriminated union narrow refine ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking change in existing TypeScript/JavaScript co...
Open Graph Description: Suggestion 🔍 Search Terms rest spread element destructure destructuring discriminated union narrow refine ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking cha...
X Description: Suggestion 🔍 Search Terms rest spread element destructure destructuring discriminated union narrow refine ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/46680
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Control flow analysis for destructured rest element of discriminated union","articleBody":"# Suggestion\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n## 🔍 Search Terms\r\n\r\nrest spread element destructure destructuring discriminated union narrow refine\r\n\r\n## ✅ Viability Checklist\r\n\r\n\u003c!--\r\n Suggestions that don't meet all these criteria are very, very unlikely to be accepted.\r\n We always recommend reviewing the TypeScript design goals before investing time writing\r\n a proposal for ideas outside the scope of the project.\r\n-->\r\nMy suggestion meets these guidelines:\r\n\r\n* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n\r\n## ⭐ Suggestion\r\n\r\nA natural extension of https://github.com/microsoft/TypeScript/pull/46266 would be to support the following\r\n\r\n```ts\r\ntype Action =\r\n | { kind: 'A', payload: number }\r\n | { kind: 'B', payload: string };\r\n\r\nfunction example({ kind, ...rest }: Action) {\r\n if (kind === 'A') {\r\n rest.payload.toFixed();\r\n }\r\n if (kind === 'B') {\r\n rest.payload.toUpperCase();\r\n }\r\n}\r\n```\r\n\r\n## 📃 Motivating Example\r\n\r\n\u003c!--\r\n If you were announcing this feature in a blog post, what's a short explanation that shows\r\n a developer why this feature improves the language?\r\n-->\r\n\r\n## 💻 Use Cases\r\n\r\n\u003c!--\r\n What do you want to use this for?\r\n What shortcomings exist with current approaches?\r\n What workarounds are you using in the meantime?\r\n-->\r\n","author":{"url":"https://github.com/lazytype","@type":"Person","name":"lazytype"},"datePublished":"2021-11-04T03:46:58Z","url":"https://github.com/microsoft/TypeScript/issues/46680"}
| 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:ec602a53-3bd4-4e4b-c517-67a4593f347e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 906C:222D8A:C2F44:114012:6B04636B |
| html-safe-nonce | b743e063149bcf999cc48330fb7dce330d04130db512d88d163008f6a2d7a528 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDZDOjIyMkQ4QTpDMkY0NDoxMTQwMTI6NkIwNDYzNkIiLCJ2aXNpdG9yX2lkIjoiMzk4MDQ2MTAzNzU3NjI4Mjk4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 15825081e11a57bfd3f8311a783ad4a4ce4a36fd76b590e0bbab93783859d201 |
| hovercard-subject-tag | issue:1044334807 |
| 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/46680/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6467fe7b7ad456acea4fd023326461c707c7c6f5b6c5863547e96148debce000/microsoft/TypeScript/issues/46680 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6467fe7b7ad456acea4fd023326461c707c7c6f5b6c5863547e96148debce000/microsoft/TypeScript/issues/46680 |
| og:image:alt | Suggestion 🔍 Search Terms rest spread element destructure destructuring discriminated union narrow refine ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking cha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lazytype |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| 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 | 03e114520787ad27289207f153520ef97461127c |
| 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