Title: Wrongly infers any[] from Array.prototype.flat, Array.prototype.concat · Issue #29604 · microsoft/TypeScript · GitHub
Open Graph Title: Wrongly infers any[] from Array.prototype.flat, Array.prototype.concat · Issue #29604 · microsoft/TypeScript
X Title: Wrongly infers any[] from Array.prototype.flat, Array.prototype.concat · Issue #29604 · microsoft/TypeScript
Description: TypeScript Version: 3.2.4, 3.3.0-dev.20190126 Search Terms: array, flat, concat, any, unsound Code const a: boolean[] = [[17], ["foo"]].flat(); // wrongly accepted const b: boolean[] = Array.prototype.concat([17], [19], [21]); // wrongly...
Open Graph Description: TypeScript Version: 3.2.4, 3.3.0-dev.20190126 Search Terms: array, flat, concat, any, unsound Code const a: boolean[] = [[17], ["foo"]].flat(); // wrongly accepted const b: boolean[] = Array.protot...
X Description: TypeScript Version: 3.2.4, 3.3.0-dev.20190126 Search Terms: array, flat, concat, any, unsound Code const a: boolean[] = [[17], ["foo"]].flat(); // wrongly accepted const b: boolean[] = Ar...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/29604
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wrongly infers any[] from Array.prototype.flat, Array.prototype.concat","articleBody":"**TypeScript Version:** 3.2.4, 3.3.0-dev.20190126\r\n\r\n**Search Terms:** array, flat, concat, any, unsound\r\n\r\n**Code**\r\n\r\n```ts\r\nconst a: boolean[] = [[17], [\"foo\"]].flat(); // wrongly accepted\r\nconst b: boolean[] = Array.prototype.concat([17], [19], [21]); // wrongly accepted\r\n```\r\n\r\nUsing `tsc --strict -t esnext`.\r\n\r\n(What I’m really trying to do: find a type safe way to concatenate an array of arrays. It’d be nice if `[].concat(...arrays)` were accepted, which I think would be a consequence of #26976, but that’s not the issue I’m reporting here. `arrays.flat()` and `Array.prototype.concat(...arrays)` are accepted but apparently provide no type safety.)\r\n\r\n**Expected behavior:** `[[17], [\"foo\"]].flat()` should be typed `(number | string)[]` (if it’s accepted at all), and `Array.prototype.concat([17], [19], [21])` should be typed `number[]`. In both cases the assignment to `boolean[]` should be rejected.\r\n\r\n**Actual behavior:** TypeScript infers `any[]` for both right hand sides (even with `--noImplicitAny` implied by `--strict`), and accepts the assignments to `boolean[]` with no complaints.\r\n\r\n**Playground Link:** Playground doesn’t support `esnext`, but here’s the [second line](https://www.typescriptlang.org/play/#src=const%20b%3A%20boolean%5B%5D%20%3D%20Array.prototype.concat(%5B17%5D%2C%20%5B19%5D%2C%20%5B21%5D)%3B).\r\n\r\n**Related Issues:** #19535 for `concat` (but that one may have more to do with the difficulty of typing `concat`’s weird behavior when non-arrays are passed?), #26976","author":{"url":"https://github.com/andersk","@type":"Person","name":"andersk"},"datePublished":"2019-01-26T10:15:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":28},"url":"https://github.com/29604/TypeScript/issues/29604"}
| 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:bd513edb-94ba-d56d-9a25-567c0c7ed409 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4B8:2046A1:8C98DC:CA02C9:6A62170B |
| html-safe-nonce | 8d5e63b6a20001e9cc7b0136c1df6fddab889aa2187d6623b50c561d0c7af730 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEI4OjIwNDZBMTo4Qzk4REM6Q0EwMkM5OjZBNjIxNzBCIiwidmlzaXRvcl9pZCI6Ijc0Njc3NTYzMTkwNTM4NDYyODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e5c9ef3c7eb2af5c669d9871c012803424c908302e4535471246b03149a0ab2a |
| hovercard-subject-tag | issue:403427134 |
| 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/29604/issue_layout |
| twitter:image | https://opengraph.githubassets.com/392e3e7e100033c46c7f84553a883c7d4d4e81333767f3424300aa8aa99afe4a/microsoft/TypeScript/issues/29604 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/392e3e7e100033c46c7f84553a883c7d4d4e81333767f3424300aa8aa99afe4a/microsoft/TypeScript/issues/29604 |
| og:image:alt | TypeScript Version: 3.2.4, 3.3.0-dev.20190126 Search Terms: array, flat, concat, any, unsound Code const a: boolean[] = [[17], ["foo"]].flat(); // wrongly accepted const b: boolean[] = Array.protot... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andersk |
| hostname | github.com |
| expected-hostname | github.com |
| None | ccf61cb7ab435725b916ed640f57c45b2c4721db9469bc32656080efc5214b3e |
| 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 | a7585b3d2ee639495a70ce464d0a18bad88ea12c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width