Title: Implement "this" type for intersection and union types · Issue #10591 · microsoft/TypeScript · GitHub
Open Graph Title: Implement "this" type for intersection and union types · Issue #10591 · microsoft/TypeScript
X Title: Implement "this" type for intersection and union types · Issue #10591 · microsoft/TypeScript
Description: TypeScript Version: 1.8.0 It seems that polymorphic 'this' types don't apply as expected to intersection and union types. Motivating Example: Lightweight Mixins This example was forked from the proposal on polymorphic 'this' types consid...
Open Graph Description: TypeScript Version: 1.8.0 It seems that polymorphic 'this' types don't apply as expected to intersection and union types. Motivating Example: Lightweight Mixins This example was forked from the pro...
X Description: TypeScript Version: 1.8.0 It seems that polymorphic 'this' types don't apply as expected to intersection and union types. Motivating Example: Lightweight Mixins This example was forked ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10591
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implement \"this\" type for intersection and union types","articleBody":"**TypeScript Version:** 1.8.0\n\nIt seems that polymorphic 'this' types don't apply as expected to intersection and union types.\n# Motivating Example: Lightweight Mixins\n\nThis example was forked from the proposal on [polymorphic 'this' types](https://github.com/Microsoft/TypeScript/issues/3694) considering \"lightweight mixin\"s. Unfortunately, the model can only be extended once because 'this' only includes \"real\" class extensions and no union type extensions as shown in the example. That's why the current implementation doesn't help us with the specified example.\n\n``` ts\ninterface Model {\n extend\u003cT>(t: T): this & T;\n}\n\ninterface NamedModel extends Model {\n name: string;\n}\n\ndeclare function createNamedModel(): NamedModel;\n\nvar extendedModel = createNamedModel().extend({\n age: 30\n}).extend({\n job: \"programmer\"\n});\nextendedModel.name; // valid\nextendedModel.job; // valid\nextendedModel.age; // error: Property 'age' does not exist because type is NamedModel & { job: string }\n```\n# Suggestion\n\nI suggest allowing the following:\n\n``` ts\ninterface A {\n getThis(): this;\n}\n\nlet extended: A & { y: string };\nextended.getThis().y;\n```\n\nThis would require to assign intersection and union types to \"this\" instead of only superclasses of A. As far as I can see, this should not be too complicated/invasive, is it? I could not find any explicit decision against this feature, so maybe it's kind of a bug?\n","author":{"url":"https://github.com/datokrat","@type":"Person","name":"datokrat"},"datePublished":"2016-08-29T14:49:11Z","url":"https://github.com/microsoft/TypeScript/issues/10591"}
| 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:d0e7bc7b-3481-4b4a-1c24-58bc203bf60b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC8E:16AB79:3EE78A:51647F:6B00D468 |
| html-safe-nonce | 84f11b080c562caf9b7ebfcf3d772b3f1723ad06444a427df056f13b9e1484cf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzhFOjE2QUI3OTozRUU3OEE6NTE2NDdGOjZCMDBENDY4IiwidmlzaXRvcl9pZCI6IjU4NTA3MzgxNzYyMTMxNzc0NDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a8f438e3119a9868cf576bd6d08c87f8c881a409e9e5b8f4a461335277e68f8c |
| hovercard-subject-tag | issue:173792546 |
| 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/10591/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ef46a7e09d67ac80215b6d756002c000561bfe5690cfb0168ece141034d152c9/microsoft/TypeScript/issues/10591 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ef46a7e09d67ac80215b6d756002c000561bfe5690cfb0168ece141034d152c9/microsoft/TypeScript/issues/10591 |
| og:image:alt | TypeScript Version: 1.8.0 It seems that polymorphic 'this' types don't apply as expected to intersection and union types. Motivating Example: Lightweight Mixins This example was forked from the pro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | datokrat |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| 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 | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width