Title: Inference to generic class without explicit constructor fails · Issue #35636 · microsoft/TypeScript · GitHub
Open Graph Title: Inference to generic class without explicit constructor fails · Issue #35636 · microsoft/TypeScript
X Title: Inference to generic class without explicit constructor fails · Issue #35636 · microsoft/TypeScript
Description: TypeScript Version: 3.5.1+ Search Terms: generic class constructor inference Code class C
Open Graph Description: TypeScript Version: 3.5.1+ Search Terms: generic class constructor inference Code class C
X Description: TypeScript Version: 3.5.1+ Search Terms: generic class constructor inference Code class C<T> {} declare function f<InstanceT>(Constructor: new () => InstanceT): void // `InstanceType...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35636
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inference to generic class without explicit constructor fails","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n**TypeScript Version:** 3.5.1+\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** generic class constructor inference\r\n\r\n**Code**\r\n\r\n```ts\r\nclass C\u003cT> {}\r\ndeclare function f\u003cInstanceT>(Constructor: new () => InstanceT): void\r\n\r\n// `InstanceType` should be inferred as `C\u003cunknown>`, but is `unknown`\r\nf(C)\r\n\r\n```\r\n\r\n**Expected behavior:**\r\n`InstanceType` should be inferred as `C\u003cunknown>`\r\n\r\n**Actual behavior:**\r\n`InstanceType` should be inferred as `unknown`\r\n\r\nNonsensical workarounds:\r\n\r\n- add an explicit constructor to `C`\r\n- add an unused type parameter to the `Constructor` parameter type, e.g. `new \u003cT>() => InstanceT`\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/?ts=3.5.1&ssl=1&ssc=1&pln=7&pc=1#code/CYUwxgNghgTiAEkoGdnwMIB4AqA+eA3gFAC+RRoSc8AZgK4B2YALgJYD2DtmAkg8syhMQeABTpOAmHRbsYALngMQAd3iiAlPAC8+PgKFgRGxQDd2rYORriNRIA","author":{"url":"https://github.com/andrewbranch","@type":"Person","name":"andrewbranch"},"datePublished":"2019-12-11T22:21:00Z","url":"https://github.com/microsoft/TypeScript/issues/35636"}
| 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:0bd0c28d-f200-fd03-7625-88ffe4b328fc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C258:14ECB:7F7E23:A411C3:6B00E7A2 |
| html-safe-nonce | 839a9ccad28ef95873dead71b102d3dac5bd497948cfaebda29fc8929a264cc4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjU4OjE0RUNCOjdGN0UyMzpBNDExQzM6NkIwMEU3QTIiLCJ2aXNpdG9yX2lkIjoiNDMwMzExOTA4OTg4ODQ1NDU2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2af9245fc4218b2ed49b753067894fec58d79865c37465700eed5f883fc274a4 |
| hovercard-subject-tag | issue:536646525 |
| 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/35636/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cdd6d0bfae249b799115deba849fda89fbde091b2e2cd728458081be138c34e7/microsoft/TypeScript/issues/35636 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cdd6d0bfae249b799115deba849fda89fbde091b2e2cd728458081be138c34e7/microsoft/TypeScript/issues/35636 |
| og:image:alt | TypeScript Version: 3.5.1+ Search Terms: generic class constructor inference Code class C |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andrewbranch |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width