Title: Type inference not working for this particular use of Generics? · Issue #8952 · microsoft/TypeScript · GitHub
Open Graph Title: Type inference not working for this particular use of Generics? · Issue #8952 · microsoft/TypeScript
X Title: Type inference not working for this particular use of Generics? · Issue #8952 · microsoft/TypeScript
Description: Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of the type inference mechanism, or if my declaration...
Open Graph Description: Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of the type i...
X Description: Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of th...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/8952
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type inference not working for this particular use of Generics?","articleBody":"Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of the type inference mechanism, or if my declaration doesn't mean what I think it means. it's a bit similar to the “Curiously recurring template pattern” described on #5949, but isn't actually the CRTP, since there's no actual recursion involved. Thanks in advance for looking into this issue.\n\n**TypeScript Version:** \n\n1.8.10\n\n**Code**\n\n``` ts\ninterface IFoo {\n foo: 'foo'; // Could be anything\n}\n\ninterface IWrapped\u003cI> {\n getObject(): I;\n}\n\nfunction unwrap\u003cI, T extends IWrapped\u003cI>>(x: T): I {\n return x.getObject();\n}\n\nlet x: IWrapped\u003cIFoo>/* = ... */;\nlet y = unwrap\u003cIFoo, IWrapped\u003cIFoo>>(x); // Type is IFoo (correct)\nlet z = unwrap(x); // Type is {} (incorrect?)\n```\n\n**Expected behavior:**\n\nI expected the compiler to infer the type of `z` as being `IFoo`, like when using explicit generic parameters on `y`.\n\n**Actual behavior:** \n\nThe compiler inferred the type of `z` as being `{}`.\n","author":{"url":"https://github.com/coreh","@type":"Person","name":"coreh"},"datePublished":"2016-06-03T06:09:53Z","url":"https://github.com/microsoft/TypeScript/issues/8952"}
| 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:6ae32efa-8447-1caf-43a2-d87bb1f80b54 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8268:2E5652:5C2063:772E6F:6B00DD43 |
| html-safe-nonce | 16e393998d2e47b59865aeca4041f9e16d06b3f429ce5e61771c99b67dda6f5d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjY4OjJFNTY1Mjo1QzIwNjM6NzcyRTZGOjZCMDBERDQzIiwidmlzaXRvcl9pZCI6IjUzMzc0MDI0MjIyNzQ4NzQ2OTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 333fcce4b2031b0bf076c8e9438aebcd562f5baa279d68fdaaed8207c8c56863 |
| hovercard-subject-tag | issue:158297869 |
| 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/8952/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c8d5624c846e8912f0a57c8e164d70ede7360bec7fa1b12cdff5adcb7defd40c/microsoft/TypeScript/issues/8952 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c8d5624c846e8912f0a57c8e164d70ede7360bec7fa1b12cdff5adcb7defd40c/microsoft/TypeScript/issues/8952 |
| og:image:alt | Hey there. I was experimenting with generics, and noticed that type inference didn't work as I expected for this particular case. I'm not entirely sure if this is an actual blind spot of the type i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | coreh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width