Title: Tuple iteration and merging · Issue #26058 · microsoft/TypeScript · GitHub
Open Graph Title: Tuple iteration and merging · Issue #26058 · microsoft/TypeScript
X Title: Tuple iteration and merging · Issue #26058 · microsoft/TypeScript
Description: Edit: Remove indexing part Edit 2: Replace tuple mapping syntax with normal mapped types Search Terms Concatentate and merge tuples' entries. Suggestion I would like to be able to extract and spread in positions other than the last part ...
Open Graph Description: Edit: Remove indexing part Edit 2: Replace tuple mapping syntax with normal mapped types Search Terms Concatentate and merge tuples' entries. Suggestion I would like to be able to extract and sprea...
X Description: Edit: Remove indexing part Edit 2: Replace tuple mapping syntax with normal mapped types Search Terms Concatentate and merge tuples' entries. Suggestion I would like to be able to extract and s...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26058
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tuple iteration and merging","articleBody":"**Edit:** Remove indexing part\r\n**Edit 2:** Replace tuple mapping syntax with [normal mapped types](https://github.com/Microsoft/TypeScript/pull/26063)\r\n\r\n## Search Terms\r\n\r\n\u003c!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily --\u003e\r\n\r\nConcatentate and merge tuples' entries.\r\n\r\n## Suggestion\r\n\r\n\u003c!-- A summary of what you'd like to see added or changed --\u003e\r\n\r\n1. I would like to be able to extract and spread in positions other than the last part of a tuple.\r\n1. I would like to merge a tuple into an intersection or concatenation of its members.\r\n\r\n## Use Cases\r\n\r\n\u003c!--\r\nWhat do you want to use this for?\r\nWhat shortcomings exist with current approaches?\r\n--\u003e\r\n\r\n- Converting a tuple to its intersection, such as with `Object.assign`'s assignee.\r\n- Typing `Array.prototype.concat` correctly for tuples.\r\n\r\n## Syntax\r\n\r\nThe syntax comes in a few new forms:\r\n\r\n- `[...A, B]` appends `B` to the tuple `A`. Similarly, `[...infer A, any] extends B ? A : []` drops the last item of the tuple and `[...any[], infer A] extends B ? A : never` extracts the first.\r\n- `{... ...T}` for an n-ary merge and `[... ...T]` an n-ary concatenation.\r\n\r\n## Examples\r\n\r\nHere's the types for each method I mentioned above.\r\n\r\n```ts\r\ninterface Array\u003cT\u003e {\r\n concat\u003cU extends any[]\u003e(...others: U): [...this, ... ...{[I in keyof U]: (\r\n U[I] extends any[] ? N : U[I] extends ArrayLike\u003cinfer R\u003e ? R[] : [U[I]]\r\n )}];\r\n}\r\n\r\ninterface ObjectConstructor {\r\n assign(target: {... ...typeof sources}, ...sources: object[]): typeof target;\r\n}\r\n```\r\n\r\n\u003c!-- Show how this would be used and what the behavior would be --\u003e\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\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. new expression-level syntax)","author":{"url":"https://github.com/dead-claudia","@type":"Person","name":"dead-claudia"},"datePublished":"2018-07-30T06:57:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/26058/TypeScript/issues/26058"}
| 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:bb9d0396-73f6-c25a-0b39-e89083d9313e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8870:E15B5:3C11B0:55D166:6A622164 |
| html-safe-nonce | af512e5a74df565442a5a911d51bef8f1ef5d5a3f1cf9bc567ab2c6400f3ef68 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODcwOkUxNUI1OjNDMTFCMDo1NUQxNjY6NkE2MjIxNjQiLCJ2aXNpdG9yX2lkIjoiNjc4MTkyNDc3ODYwODU2NjYyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0a4d2be21fe35bf84bdaccc642a8c7018ca250aec9e83b0f3104d160ccd28c52 |
| hovercard-subject-tag | issue:345633672 |
| 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/26058/issue_layout |
| twitter:image | https://opengraph.githubassets.com/11335c0d05919b2ed0c0014a9f8bff9afffa624ad685985f18064c6d5c97df5f/microsoft/TypeScript/issues/26058 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/11335c0d05919b2ed0c0014a9f8bff9afffa624ad685985f18064c6d5c97df5f/microsoft/TypeScript/issues/26058 |
| og:image:alt | Edit: Remove indexing part Edit 2: Replace tuple mapping syntax with normal mapped types Search Terms Concatentate and merge tuples' entries. Suggestion I would like to be able to extract and sprea... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dead-claudia |
| hostname | github.com |
| expected-hostname | github.com |
| None | be68eaf9abf2a202afbd94047d7200fb88b7edb0338f533bf171bbb1a69fab4e |
| 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 | 3d00b04c8874615454dfbdb32a7d2ca4db66d3f4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width