Title: Contextual type for an array element doesn't filter out non-array union members · Issue #52588 · microsoft/TypeScript · GitHub
Open Graph Title: Contextual type for an array element doesn't filter out non-array union members · Issue #52588 · microsoft/TypeScript
X Title: Contextual type for an array element doesn't filter out non-array union members · Issue #52588 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms array tuple contextual type inference union implicit any 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link with relevant code 💻 Code declare funct...
Open Graph Description: Bug Report 🔎 Search Terms array tuple contextual type inference union implicit any 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link...
X Description: Bug Report 🔎 Search Terms array tuple contextual type inference union implicit any 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/52588
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Contextual type for an array element doesn't filter out non-array union members","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\narray tuple contextual type inference union implicit any\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.0.0-dev.20230203#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxAGcMAKAKHnlgHMAueAJXBxmAB4SYtUaAaeKVoMuPGgEp4AXgB88AG44swOQB94AQRgwoAT3ZCY9eKmQBbAEYgYk2QqUry4houUBucuUIlSAbUqCtLZyAN4BVLRu8AD00dSYyFAQDFCoulEgAB4ADuCEwAymltYBAL585AC64h5AA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ndeclare function test(\r\n arg: Record\u003cstring, (arg: string) => void> | Array\u003c(arg: number) => void>\r\n): void;\r\n\r\ntest([\r\n (arg) => {\r\n arg; // actual: any; expected: number\r\n },\r\n]);\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe contextual type for array element is sourcing the information from the string indexer of the `Record` type. This makes the contextual type of this function to be `((arg: string) => void) | ((arg: number) => void)`. The contravariant position of `arg` makes its type reduce to `never` (since it's `string & number`) and prevents the expected contextual type to be provided.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI'd expect this contextual type to only be sourced from the `Array` member\r\n","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2023-02-03T13:22:14Z","url":"https://github.com/microsoft/TypeScript/issues/52588"}
| 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:fa23888d-c732-f21e-191f-86d14a799672 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D708:ADA9D:2CBC028:3965362:6B01AA9F |
| html-safe-nonce | 1957235bcbddc05bbf437900d8587525c6d91c4071aaf7acae1f0e7baa65657c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzA4OkFEQTlEOjJDQkMwMjg6Mzk2NTM2Mjo2QjAxQUE5RiIsInZpc2l0b3JfaWQiOiI4Mjc5MTc1Mjk3NDA0ODczMzc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fbe29e4d0fcd5cfa2f6c7e721a19c4212f7c602b733ac4e156d3babdae2345b1 |
| hovercard-subject-tag | issue:1569836924 |
| 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/52588/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7a18e028440abd7f3fd36f5b9e1cfb8e2f5bb5f3eea790459336f22ba300d1b3/microsoft/TypeScript/issues/52588 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7a18e028440abd7f3fd36f5b9e1cfb8e2f5bb5f3eea790459336f22ba300d1b3/microsoft/TypeScript/issues/52588 |
| og:image:alt | Bug Report 🔎 Search Terms array tuple contextual type inference union implicit any 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andarist |
| 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