Title: Polymorphic `this` and Generics · Issue #6223 · microsoft/TypeScript · GitHub
Open Graph Title: Polymorphic `this` and Generics · Issue #6223 · microsoft/TypeScript
X Title: Polymorphic `this` and Generics · Issue #6223 · microsoft/TypeScript
Description: First, thank you team for polymorphic this. It is really handy! I think I ran into a case though that I am finding challenging, when I need to return a this, but the generics might have changed. For example: class A
Open Graph Description: First, thank you team for polymorphic this. It is really handy! I think I ran into a case though that I am finding challenging, when I need to return a this, but the generics might have changed. Fo...
X Description: First, thank you team for polymorphic this. It is really handy! I think I ran into a case though that I am finding challenging, when I need to return a this, but the generics might have changed. Fo...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6223
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Polymorphic `this` and Generics","articleBody":"First, thank you team for polymorphic `this`. It is really handy!\n\nI think I ran into a case though that I am finding challenging, when I need to return a `this`, but the generics might have changed. For example:\n\n``` typescript\nclass A\u003cT> {\n private items: T[] = [];\n map\u003cU>(callback: (item: T, idx: number, a: this) => U): this {\n // boring implementation details\n });\n}\n```\n\nWhere I want to be able to change the generic type for the class with a function, but I will be contracting to return the \"current\" class, but I want to guard different generics. The following seems logical to me, but doesn't appear to be currently supported:\n\n``` typescript\nclass A\u003cT> {\n private items: T[] = [];\n map\u003cU>(callback: (item: T, idx: number, a: this) => U): this\u003cU> {\n // boring implementation details\n });\n}\n```\n\nWhere if no generics arguments are supplied, it is inferred to be the current ones, where as if they are supplied they are substituted.\n","author":{"url":"https://github.com/kitsonk","@type":"Person","name":"kitsonk"},"datePublished":"2015-12-23T11:35:23Z","url":"https://github.com/microsoft/TypeScript/issues/6223"}
| 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:ccd286e6-a8f8-ade8-25f4-2a811caa0df9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E15E:20AA01:106219B:14F7B06:6B0101D2 |
| html-safe-nonce | 9c61e203710bbd534f8347c8805d5889ab39e21fb80bd48aa2cd63b9a8bf2788 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTVFOjIwQUEwMToxMDYyMTlCOjE0RjdCMDY6NkIwMTAxRDIiLCJ2aXNpdG9yX2lkIjoiNzM4NDk3NjcyMTQyMzk1ODQ4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c6558678142d6e25245edc2685cbee1ceae5ab6b62cad677626335937ed575ff |
| hovercard-subject-tag | issue:123644145 |
| 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/6223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/383fb8f1c1ff13b2c15a783f939e70f1e46ef4ad16cb156e46ebb07c1e362fbb/microsoft/TypeScript/issues/6223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/383fb8f1c1ff13b2c15a783f939e70f1e46ef4ad16cb156e46ebb07c1e362fbb/microsoft/TypeScript/issues/6223 |
| og:image:alt | First, thank you team for polymorphic this. It is really handy! I think I ran into a case though that I am finding challenging, when I need to return a this, but the generics might have changed. Fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kitsonk |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width