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:d1d2793e-a162-bd13-d187-2b7540b39237 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EAFA:65478:6AFFF0:903FBB:6B00D72E |
| html-safe-nonce | 6da464133d9a66cb1abd65f3c93a384438b17cea1399b8370d7434b77cece10e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUZBOjY1NDc4OjZBRkZGMDo5MDNGQkI6NkIwMEQ3MkUiLCJ2aXNpdG9yX2lkIjoiNzU4MzkxNDE5MDYyMDkwNzMxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 771d465e874700303b80d1e63e5a1a78dc5efecc5aa8ecba1643c0c8e250576e |
| 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 | 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