Title: Exposing type and object from class factories. · Issue #13798 · microsoft/TypeScript · GitHub
Open Graph Title: Exposing type and object from class factories. · Issue #13798 · microsoft/TypeScript
X Title: Exposing type and object from class factories. · Issue #13798 · microsoft/TypeScript
Description: Following the great mixin implementation by Anders Hejlsberg (@ahejlsberg) (#13743) Having a mixin function returns a class is powerful but requires manual type declaration. interface Tagged { _tag: string; } class Point { constructor(pu...
Open Graph Description: Following the great mixin implementation by Anders Hejlsberg (@ahejlsberg) (#13743) Having a mixin function returns a class is powerful but requires manual type declaration. interface Tagged { _tag...
X Description: Following the great mixin implementation by Anders Hejlsberg (@ahejlsberg) (#13743) Having a mixin function returns a class is powerful but requires manual type declaration. interface Tagged { _tag...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/13798
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Exposing type and object from class factories.","articleBody":"Following the great mixin implementation by @ahejlsberg (#13743)\r\n\r\nHaving a mixin function returns a class is powerful but requires manual type declaration.\r\n\r\n```ts\r\ninterface Tagged {\r\n _tag: string;\r\n}\r\n\r\nclass Point {\r\n constructor(public x: number, public y: number) {}\r\n}\r\n\r\ntype Constructor\u003cT> = new(...args: any[]) => T;\r\n\r\nfunction Tagged\u003cT extends Constructor\u003c{}>>(Base: T) {\r\n return class extends Base {\r\n _tag: string;\r\n constructor(...args: any[]) {\r\n super(...args);\r\n this._tag = \"\";\r\n }\r\n }\r\n}\r\n\r\nexport const TaggedPoint: Constructor\u003cTagged> & typeof Point = Tagged(Point);\r\nconst tPoint: TaggedPoint; // ERROR: Cannot find name 'TaggedPoint'\r\n```\r\n\r\nWe can't use `TaggedPoint` as a type, unless we:\r\n```ts\r\nexport type TaggedPoint = Constructor\u003cTagged> & typeof Point;\r\nconst tPoint: TaggedPoint; // NOW OK\r\n```\r\n\r\nUsing classes we can\r\n```ts\r\nexport class Customer extends Tagged(Person) {\r\n accountBalance: number;\r\n}\r\n```\r\nWhich exposes the type **but** forces the developer to `extend` the `Customer` class.\r\n\r\nMy feature request is allowing:\r\n```ts\r\nexport class TaggedPoint = Tagged(Point);\r\n```\r\n\r\nWhich will be just sugar for: \r\n```ts\r\nexport const TaggedPoint = Tagged(Point);\r\nexport type TaggedPoint = Constructor\u003cTagged> & typeof Point;\r\n```\r\n\r\nMaybe even:\r\n```ts\r\nexport class TaggedPoint = Tagged(Point) { // user can extend here...\r\n}\r\n```\r\nbut that's not the main point...\r\n\r\nThe motivation for this is a more robust mixin mechanism that revolves around the base class and allow mixin's to know about it, using generic it provides powerful combinations.\r\n\r\n\r\nSo I can have\r\n```ts\r\nRestMixin(Base, Mixin1, Mixin2);\r\n```\r\n\r\nAnd the return type can have members from Mixin1 knowning about Base, using interfaces one can even set static members of a mixin to return T which is the instance of `RestMixin(Base, Mixin1, Mixin2)` all together.","author":{"url":"https://github.com/shlomiassaf","@type":"Person","name":"shlomiassaf"},"datePublished":"2017-02-01T00:45:32Z","url":"https://github.com/microsoft/TypeScript/issues/13798"}
| 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:19891e3a-ecb7-f44f-01b8-58928220f254 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 918C:D0E46:7102D0:9732DA:6B00D7C7 |
| html-safe-nonce | 7c65e1556cf11b35569ebaaedda911c150c081c2225da599af05699621d4b683 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MThDOkQwRTQ2OjcxMDJEMDo5NzMyREE6NkIwMEQ3QzciLCJ2aXNpdG9yX2lkIjoiMTE3MDQ3Nzk1ODMxODU3NzYwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 577fe518e4fd934cf3efd3c2dc770631c374158b3d4ea4b0954b8693c93b9980 |
| hovercard-subject-tag | issue:204467526 |
| 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/13798/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d0dff554588ae6913f2c43f80e058c6477e2344f6f034e00b369f2232554b38d/microsoft/TypeScript/issues/13798 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d0dff554588ae6913f2c43f80e058c6477e2344f6f034e00b369f2232554b38d/microsoft/TypeScript/issues/13798 |
| og:image:alt | Following the great mixin implementation by Anders Hejlsberg (@ahejlsberg) (#13743) Having a mixin function returns a class is powerful but requires manual type declaration. interface Tagged { _tag... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shlomiassaf |
| hostname | github.com |
| expected-hostname | github.com |
| None | a481f62a1e04c9b9bdcb5628230682c66d59006f5b13b080f79cba84a176905b |
| 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 | 84c8c5cc25e2fb7f2308428458538436baecc6d2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width