Title: 1-tuple of union should be the same as union of 1-tuples · Issue #30895 · microsoft/TypeScript · GitHub
Open Graph Title: 1-tuple of union should be the same as union of 1-tuples · Issue #30895 · microsoft/TypeScript
X Title: 1-tuple of union should be the same as union of 1-tuples · Issue #30895 · microsoft/TypeScript
Description: Search Terms Union of singletons vs singleton of union, one-element array, single-value array, singleton. Intersection of 1-tuples should be the same as 1-tuple of the intersection. Suggestion As a 1-tuple, or single-element array, conta...
Open Graph Description: Search Terms Union of singletons vs singleton of union, one-element array, single-value array, singleton. Intersection of 1-tuples should be the same as 1-tuple of the intersection. Suggestion As a...
X Description: Search Terms Union of singletons vs singleton of union, one-element array, single-value array, singleton. Intersection of 1-tuples should be the same as 1-tuple of the intersection. Suggestion As a...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/30895
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"1-tuple of union should be the same as union of 1-tuples","articleBody":"## Search Terms\r\nUnion of singletons vs singleton of union, one-element array, single-value array, singleton.\r\nIntersection of 1-tuples should be the same as 1-tuple of the intersection.\r\n\r\n## Suggestion\r\nAs a 1-tuple, or single-element array, contains only one wrapped value, the exact same type operations that are applied to them also apply to their elements. That is, saying \"a 1-tuple containing either A or B\" is the same as saying \"either a 1-tuple containing A, or a 1-tuple containing B\". This applies both to type unions and type intersections.\r\n\r\nThis all should be true in TypeScript:\r\n```typescript\r\n[A|B|C] === [A|B] | [C] === [A] | [B] | [C]\r\n[A|B] & [C] === [(A|B)&C] === ([A]|[B])&[C]\r\n// where A === B means both A is assignable to B and B is assignable to A\r\n\r\n[A|B|C] ⊂ Array\u003cA|B|C>\r\n[A|B|C] ⊂ A[] | B[] | C[]\r\n// where A ⊂ B means A is assignable to B, but B is not assignable to A\r\n\r\n```\r\n\r\n## Use Cases\r\n```typescript\r\ntype value = string | number;\r\ntype array = string[] | number[];\r\n\r\nfunction(a: value | array)\r\n{\r\n const arr = Array.isArray(a) ? a : [a]; // this should work\r\n}\r\n```\r\n\r\n\u003c!--\r\nWhat do you want to use this for?\r\nWhat shortcomings exist with current approaches?\r\n-->\r\n\r\n## Examples\r\nSee *Use Cases*, I couldn't come up with another example that would be different enough to be worth mentioning.\r\n\r\n## Checklist\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, 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","author":{"url":"https://github.com/cshaa","@type":"Person","name":"cshaa"},"datePublished":"2019-04-12T18:40:36Z","url":"https://github.com/microsoft/TypeScript/issues/30895"}
| 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:0a343730-dbe8-4c26-1d80-bb5126f8da02 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADD6:24492B:14699D:1BC080:6AFBFC36 |
| html-safe-nonce | 45b87db8f21c21438002ffa2559f3a81bd67bbea009037829e368bd9ee5ab0ac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREQ2OjI0NDkyQjoxNDY5OUQ6MUJDMDgwOjZBRkJGQzM2IiwidmlzaXRvcl9pZCI6IjEzNzQyMTg5NzA0Nzg2NzI5NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 71204719d06a0102f0cc7661a1368bb0a0c4815a454bdcc7c8b62d7bed6969bf |
| hovercard-subject-tag | issue:432695361 |
| 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/30895/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bdfc328820d74f6942da058957d3e96a52eb133bd6563519b1116f2f1d10ad9f/microsoft/TypeScript/issues/30895 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bdfc328820d74f6942da058957d3e96a52eb133bd6563519b1116f2f1d10ad9f/microsoft/TypeScript/issues/30895 |
| og:image:alt | Search Terms Union of singletons vs singleton of union, one-element array, single-value array, singleton. Intersection of 1-tuples should be the same as 1-tuple of the intersection. Suggestion As a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cshaa |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width