Title: Feature Request / Proposal: Traits · Issue #311 · microsoft/TypeScript · GitHub
Open Graph Title: Feature Request / Proposal: Traits · Issue #311 · microsoft/TypeScript
X Title: Feature Request / Proposal: Traits · Issue #311 · microsoft/TypeScript
Description: ORIGINALLY PROPOSED IN http://typescript.codeplex.com/workitem/838 Traits, as "compile-time" partial classes, would perfectly fit with TS ideology and resolve problems of multiple inheritance/mixins. Traits in Scala: http://en.wikibooks....
Open Graph Description: ORIGINALLY PROPOSED IN http://typescript.codeplex.com/workitem/838 Traits, as "compile-time" partial classes, would perfectly fit with TS ideology and resolve problems of multiple inheritance/mixin...
X Description: ORIGINALLY PROPOSED IN http://typescript.codeplex.com/workitem/838 Traits, as "compile-time" partial classes, would perfectly fit with TS ideology and resolve problems of multiple inherit...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/311
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Request / Proposal: Traits","articleBody":"ORIGINALLY PROPOSED IN http://typescript.codeplex.com/workitem/838\n\nTraits, as \"compile-time\" partial classes, would perfectly fit with TS ideology and resolve problems of multiple inheritance/mixins.\n\nTraits in Scala: http://en.wikibooks.org/wiki/Scala/Traits\nTraits in PHP: http://php.net/trait\n\nI propose minimal traits similar to PHP implementation.\n\n``` typescript\ntrait FooTrait {\n // same as class definition, but no constructor allowed, e.g.:\n public foo() {\n return \"foo\";\n }\n private bar() {\n return \"bar\";\n }\n}\n\nclass Foo {\n import FooTrait; //not insisting on exact keyword and syntax, just smth to start with\n\n // ...\n}\n\nclass Bar {\n // rename methods:\n import FooTrait(foo => tfoo, bar => tbar);\n\n // and to include another trait, there is another import line:\n // import BarTrait;\n\n // ...\n}\n```\n\nThe code above could be compiled to JS below (can be optimized, just showing the main idea):\n\n``` javascript\nvar FooTrait = (function () {\n function FooTrait() {\n throw \"Cannot instantiate trait FooTrait\";\n }\n FooTrait.prototype.foo = function () {\n return \"foo\";\n };\n FooTrait.prototype.bar = function () {\n return \"bar\";\n };\n return FooTrait;\n})();\n\nvar Foo = (function (_super, FooTrait) {\n function Foo() { }\n Foo.prototype.foo = FooTrait.prototype.foo;\n Foo.prototype.bar = FooTrait.prototype.bar;\n return Foo;\n})(undefined, FooTrait);\n\nvar Bar = (function (_super, FooTrait) {\n function Bar() { }\n Bar.prototype.tfoo = FooTrait.prototype.foo;\n Bar.prototype.tbar = FooTrait.prototype.bar;\n return Bar;\n})(undefined, FooTrait);\n```\n\nUnresolved name conflicts should raise a compile time error.\n\nI think it would be a great advance for the language. But the proposal has more than one year made (in codeplex) and has not yet been implemented.\n","author":{"url":"https://github.com/yasselavila","@type":"Person","name":"yasselavila"},"datePublished":"2014-07-30T15:27:49Z","url":"https://github.com/microsoft/TypeScript/issues/311"}
| 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:7f44159e-1459-072b-0f5c-06a60b6ed493 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EDC8:3C21B:2AAFDF1:368796F:6B019CAE |
| html-safe-nonce | c1e52a07521fcba6ce37c98a78ad085c3f416cf166ced3eb80834260cc0f1793 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREM4OjNDMjFCOjJBQUZERjE6MzY4Nzk2Rjo2QjAxOUNBRSIsInZpc2l0b3JfaWQiOiIxNjg1MDEzMzEyNzgwMTE1NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c7da8172502776b69065badc8f82d551b42cc512caad566d1f08240ca76c7e28 |
| hovercard-subject-tag | issue:39104093 |
| 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/311/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f5cacf29bfd6b179d91b0ed1ceb8b4d90d9698b90f3c19ac811c4a7c253f9517/microsoft/TypeScript/issues/311 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f5cacf29bfd6b179d91b0ed1ceb8b4d90d9698b90f3c19ac811c4a7c253f9517/microsoft/TypeScript/issues/311 |
| og:image:alt | ORIGINALLY PROPOSED IN http://typescript.codeplex.com/workitem/838 Traits, as "compile-time" partial classes, would perfectly fit with TS ideology and resolve problems of multiple inheritance/mixin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yasselavila |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width