Title: Support concat operations on arrays of different types · Issue #26378 · microsoft/TypeScript · GitHub
Open Graph Title: Support concat operations on arrays of different types · Issue #26378 · microsoft/TypeScript
X Title: Support concat operations on arrays of different types · Issue #26378 · microsoft/TypeScript
Description: Search Terms concat, array, type Suggestion Currently concat requires that arrays be of similar types (or arrays of arrays of similar type). This requirement can be too strict at times. Since concat doesn't change the source arrays, it s...
Open Graph Description: Search Terms concat, array, type Suggestion Currently concat requires that arrays be of similar types (or arrays of arrays of similar type). This requirement can be too strict at times. Since conca...
X Description: Search Terms concat, array, type Suggestion Currently concat requires that arrays be of similar types (or arrays of arrays of similar type). This requirement can be too strict at times. Since conca...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26378
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support concat operations on arrays of different types","articleBody":"## Search Terms\r\n\r\nconcat, array, type\r\n\r\n## Suggestion\r\n\r\nCurrently concat requires that arrays be of similar types (or arrays of arrays of similar type). This requirement can be too strict at times. Since concat doesn't change the source arrays, it seems reasonable to return an array of the union of the input array types. \r\n\r\nThis can be achieved by adding an overload to Array.concat:\r\n\r\n```\r\nArray\u003cT> {\r\n concat\u003cU>(...items: (U | ConcatArray\u003cU>)[]): Array\u003cT|U>;\r\n}\r\n```\r\n\r\n## Use Cases\r\n\r\nJoining dissimilar arrays.\r\n\r\n## Examples\r\n\r\nSimple example below. A more realistic example would probably involve arrays of more complex, type-inferred objects that are mostly similar but slightly different.\r\n\r\nconst nums=[1,2,3];\r\nconst strs = ['a','b','c'];\r\n\r\n// Currently, must do something like:\r\nconst arr1 = (nums as Array\u003cstring|number>).concat(strs);\r\n\r\n// With this proposal we can instead use:\r\nconst arr2 = nums.concat(strs);\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)\r\n\r\n","author":{"url":"https://github.com/limbo","@type":"Person","name":"limbo"},"datePublished":"2018-08-10T23:26:55Z","url":"https://github.com/microsoft/TypeScript/issues/26378"}
| 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:12d85a2a-d4c9-ced3-20a0-3598cfec5051 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85A4:10DACD:E2A2EE:12DA42F:6B01021A |
| html-safe-nonce | 65c2c546872bdf11733533522d076f15eb2e7a94250a1c96fb8894b8ce7f2311 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUE0OjEwREFDRDpFMkEyRUU6MTJEQTQyRjo2QjAxMDIxQSIsInZpc2l0b3JfaWQiOiI2NDIzMDE3MTU5Mzc4NjY2MDEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 422dc443e91bc1d71bae69e7c98e0033ca8ab4b9a63bcd5b605d3e960ad03076 |
| hovercard-subject-tag | issue:349683842 |
| 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/26378/issue_layout |
| twitter:image | https://opengraph.githubassets.com/afa31eb98846302fec240998eab80bcd967d03da5fdbfb794bc9db2ea93b1ad7/microsoft/TypeScript/issues/26378 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/afa31eb98846302fec240998eab80bcd967d03da5fdbfb794bc9db2ea93b1ad7/microsoft/TypeScript/issues/26378 |
| og:image:alt | Search Terms concat, array, type Suggestion Currently concat requires that arrays be of similar types (or arrays of arrays of similar type). This requirement can be too strict at times. Since conca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | limbo |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width