René's URL Explorer Experiment


Title: Feature: type alternatives (to facilitate traits/mixins/type decorators) · Issue #727 · microsoft/TypeScript · GitHub

Open Graph Title: Feature: type alternatives (to facilitate traits/mixins/type decorators) · Issue #727 · microsoft/TypeScript

X Title: Feature: type alternatives (to facilitate traits/mixins/type decorators) · Issue #727 · microsoft/TypeScript

Description: The type system does a great job at mirroring most type patterns in JS, all except mixins/traits, anything that decorates types - which unfortunately is very common in JS. Without it the type system remains incomplete - that is, we're st...

Open Graph Description: The type system does a great job at mirroring most type patterns in JS, all except mixins/traits, anything that decorates types - which unfortunately is very common in JS. Without it the type syste...

X Description: The type system does a great job at mirroring most type patterns in JS, all except mixins/traits, anything that decorates types - which unfortunately is very common in JS. Without it the type syste...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/727

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature: type alternatives (to facilitate traits/mixins/type decorators)","articleBody":"The type system does a great job at mirroring most type patterns in JS, all except mixins/traits, anything that decorates types - which unfortunately is very common in JS.\n\nWithout it the type system remains incomplete - that is, we're still one step short of being able to describe JavaScript mixin type patterns.\n\n[Duplication and interfaces](https://typescript.codeplex.com/wikipage?title=Mixins%20in%20TypeScript) are not the answer, because this does not reflect what's actually happening in JavaScript - e.g. not duplication, but type decoration of sorts. Not sure if I'm using the correct terminology here.\n\n[This small library](https://github.com/muut/riotjs/blob/master/lib/observable.js) is an example of a real-world decorator - duplicating all of it's method declarations in every single model type in a view-model hierarchy would be extremely impractical.\n\nThe following is a simplified example:\n\n```\nclass User {\n    public name: string;\n}\n\ninterface Events {\n    on(event: string, callback: {():void});\n    // other methods here...\n}\n\nfunction addEvents\u003cT>(object: T): T {\n    // decorate the object:\n    object['on'] = function() {\n        // ...\n    }\n    return \u003cT> {};\n}\n\nvar user = addEvents(new User());\n```\n\nThe drawback here is you have to choose which is more important - that `User` is still a `User` after being decorated by `addEvents()`, or that it is now also `Events`. There is no direct way to document this type pattern - your only option currently is to document the shape of the resulting type fully, duplicating all the member declarations contributed by the decorator.\n\nI propose syntax along the lines of the following, to support type alternatives:\n\n```\nfunction addEvents\u003cT>(object: T): T|Events {\n    // decorate the object:\n    object['on'] = function() {\n        // ...\n    }\n    return \u003cT|Events> {};\n}\n\nvar user = addEvents(new User());\n```\n\nThe return type of the call is now `User|Events` which is a distinct composite type composed members of `User` and `Events`.\n\nThe resulting composite type extends `User` and implements `Events`, and should pass type-checks for both.\n\nThis should facilitate type-safe traits/mixins and probably other arbitrary type-patterns possible in JS.\n\nStatic type-hints with composite types are implemented in this way in e.g. PhpStorm using php-doc annotations, and it works well.\n\nI think this may be a simpler and more flexible way to support mixins/traits, without explicitly adding support for those patterns specifically.\n\nThoughts?\n","author":{"url":"https://github.com/mindplay-dk","@type":"Person","name":"mindplay-dk"},"datePublished":"2014-09-23T11:58:55Z","url":"https://github.com/microsoft/TypeScript/issues/727"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:4d6c1b52-50b2-9e9c-9ffe-5486eba01f7f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC542:24C546:39E998:4DE597:6AFBE9C6
html-safe-nonce9429c72d0b14a33df88f7193702afe0aaf9d1479f77bbce850df83c688dc8bd0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTQyOjI0QzU0NjozOUU5OTg6NERFNTk3OjZBRkJFOUM2IiwidmlzaXRvcl9pZCI6IjMxNzE1MzQ2MDA1NTU3MTkxMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac9ef4d18c105dba88845fd79c89b2ca8b8521f6573160cd831e6dbbab1868c072
hovercard-subject-tagissue:43620396
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/727/issue_layout
twitter:imagehttps://opengraph.githubassets.com/67ffc8a9c2edf09ea371f293cacda88da269f328c4c0fc09d57579b8176b0e1c/microsoft/TypeScript/issues/727
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/67ffc8a9c2edf09ea371f293cacda88da269f328c4c0fc09d57579b8176b0e1c/microsoft/TypeScript/issues/727
og:image:altThe type system does a great job at mirroring most type patterns in JS, all except mixins/traits, anything that decorates types - which unfortunately is very common in JS. Without it the type syste...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemindplay-dk
hostnamegithub.com
expected-hostnamegithub.com
None744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedf859c48a4c8b4c0009c19bb4e82101aacb4b998
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/727#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F727
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F727
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/727
Reloadhttps://github.com/microsoft/TypeScript/issues/727
Reloadhttps://github.com/microsoft/TypeScript/issues/727
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests334 (334)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/pulse
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/727
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/727
Feature: type alternatives (to facilitate traits/mixins/type decorators)https://github.com/microsoft/TypeScript/issues/727#top
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Sep 23, 2014https://github.com/microsoft/TypeScript/issues/727#issue-43620396
Duplication and interfaceshttps://typescript.codeplex.com/wikipage?title=Mixins%20in%20TypeScript
This small libraryhttps://github.com/muut/riotjs/blob/master/lib/observable.js
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Sep 23, 2014https://github.com/microsoft/TypeScript/issues/727#issuecomment-56567694
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Sep 23, 2014https://github.com/microsoft/TypeScript/issues/727#issuecomment-56575524
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Sep 23, 2014https://github.com/microsoft/TypeScript/issues/727#issuecomment-56577546
https://github.com/danquirk
Dan Quirk (danquirk)https://github.com/danquirk
on Sep 23, 2014https://github.com/microsoft/TypeScript/issues/727#issuecomment-56577872
#14https://github.com/microsoft/TypeScript/issues/14
#186https://github.com/microsoft/TypeScript/issues/186
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Sep 23, 2014https://github.com/microsoft/TypeScript/issues/727#issuecomment-56581407
#14https://github.com/microsoft/TypeScript/issues/14
#186https://github.com/microsoft/TypeScript/issues/186
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Proposal%22
on Nov 26, 2014https://github.com/microsoft/TypeScript/issues/727#event-199209011
https://github.com/joewood
Joe Wood (joewood)https://github.com/joewood
on Dec 31, 2014https://github.com/microsoft/TypeScript/issues/727#issuecomment-68449830
https://github.com/benliddicott
benliddicotthttps://github.com/benliddicott
on Jul 14, 2015https://github.com/microsoft/TypeScript/issues/727#issuecomment-121372871
Joe Wood (@joewood)https://github.com/joewood
https://github.com/benliddicott
benliddicotthttps://github.com/benliddicott
on Jul 14, 2015https://github.com/microsoft/TypeScript/issues/727#issuecomment-121406077
#14https://github.com/microsoft/TypeScript/issues/14
#805https://github.com/microsoft/TypeScript/issues/805
https://github.com/benliddicott
benliddicotthttps://github.com/benliddicott
on Jul 15, 2015https://github.com/microsoft/TypeScript/issues/727#issuecomment-121643246
Rasmus Schultz (@mindplay-dk)https://github.com/mindplay-dk
#3622https://github.com/microsoft/TypeScript/pull/3622
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jul 16, 2015https://github.com/microsoft/TypeScript/issues/727#issuecomment-121781023
benliddicotthttps://github.com/benliddicott
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 16, 2015https://github.com/microsoft/TypeScript/issues/727#event-357024813
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Proposal%22
on Jul 16, 2015https://github.com/microsoft/TypeScript/issues/727#event-357024933
microsofthttps://github.com/microsoft
on Jun 18, 2018https://github.com/microsoft/TypeScript/issues/727#event-1686907993
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/727
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/727
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.