Title: Case for inference failure in `T extends F
Open Graph Title: Case for inference failure in `T extends F
X Title: Case for inference failure in `T extends F
Description: Bug Report 🔎 Search Terms circular type parameter constraint Related issues: #40439 #30134 🕗 Version & Regression Information Tested with 4.8.4 ⏯ Playground Link Playground 💻 Code declare const f:
Open Graph Description: Bug Report 🔎 Search Terms circular type parameter constraint Related issues: #40439 #30134 🕗 Version & Regression Information Tested with 4.8.4 ⏯ Playground Link Playground 💻 Code declare const f: ...
X Description: Bug Report 🔎 Search Terms circular type parameter constraint Related issues: #40439 #30134 🕗 Version & Regression Information Tested with 4.8.4 ⏯ Playground Link Playground 💻 Code declare const...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/51377
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Case for inference failure in `T extends F\u003cT>`","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\ncircular type parameter constraint\r\n\r\nRelated issues: #40439 #30134\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nTested with 4.8.4\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground](https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFwFgAoeeAHgBV4QAPDEFYNeAMQoD42AKDXecgSngBeNnyJEMATwAOCVuVFCiJAN7wovAK4oA1iiQB3FMvgAaeACNenDXyq16jeGtsBLFNhAx4ADXgBfeAB+X3heFBAANy9BEXhtPUNjYgDxQmxOFRNbACIACxAICCQc0xMreGphUWoAOgwkAFVpWRgAYSg0EE5+In9ewgB6QfhgJBA0FAByLGQAW2lXCAQLcChNLvh3TxgmAANqPfV9hP0jI-dMEChgeCRseD3MGHcAcz20jKyU3IKikrKKQqnGovGeb1iNXqTRaXg6XR6fQGw0QSAWSwmQA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ndeclare const f:\r\n \u003cT extends F\u003cT>>(t: T) => T\r\n\r\ntype F\u003cT> =\r\n { a: unknown\r\n , b: (a: T extends { a: infer X } ? X : never) => unknown\r\n }\r\n\r\nf({\r\n a: \"hello\",\r\n b: x => x.toUpperCase()\r\n})\r\n// doesn't compile because infers `x` as `unknown` instead of `string`\r\n\r\nf({\r\n a: \"hello\",\r\n b: (x: string) => x.toUpperCase()\r\n})\r\n// compiles\r\n```\r\n\r\nNote that there is a [workaround](https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFwFgAoeeAHgBV4QAPDEFYNeAMVIEEA+AGnk4AoMueJQBkLdhwCU8ALwdhRIhgCeABwStOsoiQDe8KELY74PAEZC+h3tLnwArigDWKJAHcUJgL6LC2Prom1gBEABYgEBBIwVwmFvDUsvLUAHQYSACqquowAMJQaCB8kkReJYRAA) but it's only a workaround for this minimal case and not for the real world case from which this minimal case was derived.\r\n\r\n### 🙁 Actual behavior\r\n\r\n`x` in the first `f` call gets inferred as `unknown`\r\n\r\n### 🙂 Expected behavior\r\n\r\n`x` in the first `f` call should get inferred as `string`\r\n","author":{"url":"https://github.com/devanshj","@type":"Person","name":"devanshj"},"datePublished":"2022-11-01T19:26:51Z","url":"https://github.com/microsoft/TypeScript/issues/51377"}
| 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:b885f5ee-ecc3-25da-b56b-c322b9338b09 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E12:DB09F:8B6AD9:B37213:6B00ED31 |
| html-safe-nonce | 80d7e244b11f828da143ddabec9b2b92cbc904e9fc7a72b2fa7ccd30a457e56c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTEyOkRCMDlGOjhCNkFEOTpCMzcyMTM6NkIwMEVEMzEiLCJ2aXNpdG9yX2lkIjoiMjgzMjYzMjU2MTAyMzM4MDc4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 42ebf525729ab84a9ec59c76fc706ffa30b6c8f1d4c05e053d53ca0ec5d5a198 |
| hovercard-subject-tag | issue:1431968431 |
| 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/51377/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80887f776247cf4f7997f5ffeb95b7f4bda53dfbcfd5d0c563fd266e8eee6386/microsoft/TypeScript/issues/51377 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80887f776247cf4f7997f5ffeb95b7f4bda53dfbcfd5d0c563fd266e8eee6386/microsoft/TypeScript/issues/51377 |
| og:image:alt | Bug Report 🔎 Search Terms circular type parameter constraint Related issues: #40439 #30134 🕗 Version & Regression Information Tested with 4.8.4 ⏯ Playground Link Playground 💻 Code declare const f: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devanshj |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width