Title: Array concat has wrong types · Issue #47351 · microsoft/TypeScript · GitHub
Open Graph Title: Array concat has wrong types · Issue #47351 · microsoft/TypeScript
X Title: Array concat has wrong types · Issue #47351 · microsoft/TypeScript
Description: Bug Report A not-uncommon JS idiom is [].concat(x || [], y || [], z || []) as a faster, simpler, more backwards-compatible [x, y, z].flatMap(x => x || []). However, when I try, I get type errors. 🔎 Search Terms array concat concat overlo...
Open Graph Description: Bug Report A not-uncommon JS idiom is [].concat(x || [], y || [], z || []) as a faster, simpler, more backwards-compatible [x, y, z].flatMap(x => x || []). However, when I try, I get type errors. 🔎...
X Description: Bug Report A not-uncommon JS idiom is [].concat(x || [], y || [], z || []) as a faster, simpler, more backwards-compatible [x, y, z].flatMap(x => x || []). However, when I try, I get type errors...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47351
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Array concat has wrong types","articleBody":"# Bug Report\r\n\r\nA not-uncommon JS idiom is `[].concat(x || [], y || [], z || [])` as a faster, simpler, more backwards-compatible `[x, y, z].flatMap(x => x || [])`. However, when I try, I get type errors.\r\n\r\n### 🔎 Search Terms\r\n\r\narray concat\r\nconcat overload\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about array concat\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhjAvDA2gXQHSjMOUAUAUDCTFAE4CuApjAPwwDkcjMAXKmgDTGkBmcADYRaDRgCNWHdDwCUAbkKFs0GAA8knLOFwFeJAcNFNJ7Tj1Jkqx5lPOEFQA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nconst a = [].concat(\r\n true ? 'a' : [],\r\n false ? 'b' : [],\r\n);\r\n\r\nconst x = [].concat(\r\n false ? 'b' : [],\r\n true ? 'a' : [],\r\n);\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n```\r\nNo overload matches this call.\r\n Overload 1 of 2, '(...items: ConcatArray\u003cnever>[]): never[]', gave the following error.\r\n Argument of type 'never[] | \"a\"' is not assignable to parameter of type 'ConcatArray\u003cnever>'.\r\n Type 'string' is not assignable to type 'ConcatArray\u003cnever>'.\r\n Overload 2 of 2, '(...items: ConcatArray\u003cnever>[]): never[]', gave the following error.\r\n Argument of type 'never[] | \"a\"' is not assignable to parameter of type 'ConcatArray\u003cnever>'.\r\n Type 'string' is not assignable to type 'ConcatArray\u003cnever>'.(2769)\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nNo type errors (except perhaps that the variable may be `any` until i provide an explicit type for the resulting array), because this is valid JavaScript since at least ES3.","author":{"url":"https://github.com/ljharb","@type":"Person","name":"ljharb"},"datePublished":"2022-01-08T07:18:40Z","url":"https://github.com/microsoft/TypeScript/issues/47351"}
| 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:93e16993-f250-745e-3ead-ab011bdf9336 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED00:AFBD9:D5241A:11A4F03:6B01CD98 |
| html-safe-nonce | 797bbe87279bdeb5e02db467e36f928a7ae657215f765bcd7c6f1075fbcc2f17 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDAwOkFGQkQ5OkQ1MjQxQToxMUE0RjAzOjZCMDFDRDk4IiwidmlzaXRvcl9pZCI6IjM5NjAwNjYyMTc4NjczMzMwMTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f12f369cf68b3728c091588671d509b8f6c09535be5c755cc7dc3c5d7bef3709 |
| hovercard-subject-tag | issue:1096856826 |
| 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/47351/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75557749ab0f2c467c46a83e7c95083936a2864917b30dfd1863fbd8f7684c0b/microsoft/TypeScript/issues/47351 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75557749ab0f2c467c46a83e7c95083936a2864917b30dfd1863fbd8f7684c0b/microsoft/TypeScript/issues/47351 |
| og:image:alt | Bug Report A not-uncommon JS idiom is [].concat(x || [], y || [], z || []) as a faster, simpler, more backwards-compatible [x, y, z].flatMap(x => x || []). However, when I try, I get type errors. 🔎... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ljharb |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width