Title: Unexpected union type between generic and non-generic function · Issue #12970 · microsoft/TypeScript · GitHub
Open Graph Title: Unexpected union type between generic and non-generic function · Issue #12970 · microsoft/TypeScript
X Title: Unexpected union type between generic and non-generic function · Issue #12970 · microsoft/TypeScript
Description: TypeScript Version: nightly (2.2.0) Code function id
Open Graph Description: TypeScript Version: nightly (2.2.0) Code function id
X Description: TypeScript Version: nightly (2.2.0) Code function id<T>(x: T): T { return x; } function stringId(x: string): string { return x; } function numberId(x: number): number { return x; } // OK: ((x...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12970
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected union type between generic and non-generic function","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:** nightly (2.2.0)\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction id\u003cT>(x: T): T {\r\n return x;\r\n}\r\n\r\nfunction stringId(x: string): string {\r\n return x;\r\n}\r\n\r\nfunction numberId(x: number): number {\r\n return x;\r\n}\r\n\r\n// OK: ((x: string) => string) | ((x: number) => number)\r\nconst f = true ? numberId : stringId;\r\n\r\n// Actual: \u003cT>(x: T) => T\r\n// Expected: (x: string) => string\r\nconst g = true ? id : stringId;\r\n```\r\n\r\n**Expected behavior:**\r\nUnion between a function and a generic function should yield the most specific type, not the most general one. \r\n","author":{"url":"https://github.com/gcnew","@type":"Person","name":"gcnew"},"datePublished":"2016-12-16T01:25:06Z","url":"https://github.com/microsoft/TypeScript/issues/12970"}
| 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:b2682b71-5bda-cce0-90e8-3f9b161e17ae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD16:29FFA9:5FA461:7AFEDE:6B00DD9B |
| html-safe-nonce | 72f76eb5e96ef26b94f5f10c42b73f8487632aa6719e434030acc279e7a6984c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDE2OjI5RkZBOTo1RkE0NjE6N0FGRURFOjZCMDBERDlCIiwidmlzaXRvcl9pZCI6IjI0OTc5NjY1NzA0MjUzNDMzODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d87aa085c4f5691c598fd8bc01f109d69c500f1d0803e1329ae674f5c145cab0 |
| hovercard-subject-tag | issue:195959555 |
| 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/12970/issue_layout |
| twitter:image | https://opengraph.githubassets.com/14caa489e64cfe1af479a4f0a0032e104e5b45017d73046ef091d967190c0966/microsoft/TypeScript/issues/12970 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/14caa489e64cfe1af479a4f0a0032e104e5b45017d73046ef091d967190c0966/microsoft/TypeScript/issues/12970 |
| og:image:alt | TypeScript Version: nightly (2.2.0) Code function id |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gcnew |
| 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