Title: Unification of functions on union types · Issue #34605 · microsoft/TypeScript · GitHub
Open Graph Title: Unification of functions on union types · Issue #34605 · microsoft/TypeScript
X Title: Unification of functions on union types · Issue #34605 · microsoft/TypeScript
Description: TypeScript Version: 3.6.3 Search Terms: Union type functions Code type A = number[] | string[]; const a = [1]; a.forEach(element => console.log(element)); // error Expected behavior: No compile error. (element is inferred to be number...
Open Graph Description: TypeScript Version: 3.6.3 Search Terms: Union type functions Code type A = number[] | string[]; const a = [1]; a.forEach(element => console.log(element)); // error Expected behavior: No compile ...
X Description: TypeScript Version: 3.6.3 Search Terms: Union type functions Code type A = number[] | string[]; const a = <A>[1]; a.forEach(element => console.log(element)); // error Expected behavior: No...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/34605
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unification of functions on union types","articleBody":"**TypeScript Version:** 3.6.3\r\n\r\n**Search Terms:**\r\n\r\nUnion type functions\r\n\r\n**Code**\r\n\r\n```ts\r\ntype A = number[] | string[];\r\nconst a = \u003cA>[1];\r\na.forEach(element => console.log(element)); // error\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo compile error. (`element` is inferred to be `number | string`)\r\n\r\n**Actual behavior:**\r\n\r\nCompile error. (`Parameter 'element' implicity has 'any' type.`)\r\n\r\n**Playground Link:**\r\n\r\nhttp://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=4&pc=1#code/C4TwDgpgBAglC8UB2BXAtgIwgJwNoF0oAfKAZ2GwEskBzAgbgCgBjAeyXKgEMEoAeGAD5cARnxMuAOgBmrbAFEuzABYAKCABsIaCEmAJBUNh1ZbJG1jXVadegJR36UAPTOoObHMZA\r\n\r\n**Related Issues:**\r\n\r\n---\r\n\r\nI'm unsure whether or not it is realistic to improve this. Recently I have been working with a number of `A[] | B[]` types and noticed that most array operations cannot be done on these.","author":{"url":"https://github.com/pauldraper","@type":"Person","name":"pauldraper"},"datePublished":"2019-10-20T22:22:37Z","url":"https://github.com/microsoft/TypeScript/issues/34605"}
| 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:5661ccba-dbf6-13f5-222d-b0d312110ce4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3F2:157C65:22D84FC:2E89B3E:6B0194FB |
| html-safe-nonce | 06bcca5f4f541311de22095b3d2ceb39c16918c1ad94f686b5d22b034a76bba5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0YyOjE1N0M2NToyMkQ4NEZDOjJFODlCM0U6NkIwMTk0RkIiLCJ2aXNpdG9yX2lkIjoiNjI2OTQ3MzQ3ODcwNjA0MjEwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 443d30b31455b62b143e4d838770b051839ff2b32b9df5ab423b0b9453feef54 |
| hovercard-subject-tag | issue:509661555 |
| 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/34605/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f7959390d456b45a898bd977d4b1d76c8ac7a74dd23d57b13d301475b608ae52/microsoft/TypeScript/issues/34605 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f7959390d456b45a898bd977d4b1d76c8ac7a74dd23d57b13d301475b608ae52/microsoft/TypeScript/issues/34605 |
| og:image:alt | TypeScript Version: 3.6.3 Search Terms: Union type functions Code type A = number[] | string[]; const a = [1]; a.forEach(element => console.log(element)); // error Expected behavior: No compile ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pauldraper |
| 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