René's URL Explorer Experiment


Title: Suggestion: Reopen static and instance side of classes · Issue #2957 · microsoft/TypeScript · GitHub

Open Graph Title: Suggestion: Reopen static and instance side of classes · Issue #2957 · microsoft/TypeScript

X Title: Suggestion: Reopen static and instance side of classes · Issue #2957 · microsoft/TypeScript

Description: Summary To support both the semantics of subclassing built-ins in ES6 and still allow authors to augment built-ins, we need a mechanism to reopen the static and instance sides of a class. Current state Today we can re-open interfaces, al...

Open Graph Description: Summary To support both the semantics of subclassing built-ins in ES6 and still allow authors to augment built-ins, we need a mechanism to reopen the static and instance sides of a class. Current s...

X Description: Summary To support both the semantics of subclassing built-ins in ES6 and still allow authors to augment built-ins, we need a mechanism to reopen the static and instance sides of a class. Current s...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: Reopen static and instance side of classes","articleBody":"# Summary\n\nTo support both the semantics of subclassing built-ins in ES6 and still allow authors to augment built-ins, we need a mechanism to reopen the static and instance sides of a class. \n# Current state\n\nToday we can re-open interfaces, allowing authors to augment built-ins (for example, to support polyfills):\n\n``` ts\n// in lib.d.ts\ninterface Array\u003cT> { /*...*/ }\ninterface ArrayConstructor { /*...*/ }\ndeclare var Array: ArrayConstructor;\n\n// in polyfill.ts\ninterface Array\u003cT> {\n  includes(value: T): Boolean;\n}\ninterface ArrayConstructor {\n  of\u003cT>(...items: T[]): Array\u003cT>;\n}\n\nArray.prototype.includes = function (value: any) { return this.indexOf(value) != -1; }\nArray.of = function\u003cT> (...items: T[]) { return items; }\n```\n\nWe can also re-open the static side of a class, in a limited fashion:\n\n``` ts\n// initial declaration\nclass MyClass {\n}\n\n// re-open\nmodule MyClass {\n  export var staticProperty = 1;\n}\n```\n\nThere are several issues with these approaches:\n- You cannot use type defined by the `var`/`interface` pattern in the `extends` clause of a class in TypeScript, meaning that \"classes\" defined using this pattern cannot be subclassed in ES6, which is an issue for built-ins.\n- While you can re-open the static side of a class using `module`, you can only use non-keyword identifiers for property names. So you could not, for example, add a `[Symbol.species]` property to the class, or use decorators on these members.\n- There is no way to re-open the instance side of a class.\n# Proposal\n\nI propose we add a new syntactic modifier for the `class` declaration that would indicate we are re-opening an existing class. For this example I am using the keyword `partial`, although the semantics here differ significantly than the same-named capability in C#:\n\n``` ts\n// in lib.d.ts\ndeclare class Array\u003cT> {\n}\n\n// in polyfill.ts\npartial class Array\u003cT> {\n  static of\u003cT>(...items: T[]) { return items; }\n  includes(value: T): boolean { return this.indexOf(value) != -1; }\n}\n\n// emit (ES5)\nArray.of = function() { \n  var items = [];\n  for (var _i = 0; i \u003c arguments.length; i++) \n    items[i] = arguments[i];\n  return items;\n}\nArray.prototype.includes = function(value) {\n  return this.indexOf(value) != -1;\n}\n```\n## Rules\n- A `partial` class declaration must be preceded by a non-`partial` class declaration in the same lexical scope. These should be the same rules that apply when merging a module with a class or function today.\n- A `partial` class declaration must have the same module visibility as the preceding non-`partial` class declaration.\n- A `partial` class declaration must have the same generic type parameters (including constraints) as the non-`partial` class declaration.\n- A `partial` class declaration cannot have an `extends` clause, but may have an `implements` clause.\n- A `partial` class declaration cannot have a `constructor` member.\n- A `partial` class declaration cannot have members with the same name as existing members on a class.\n  - Exception: ambient partial class declaration members can merge with other ambient partial class declaration members if they are compatible overloads, similar to interfaces.\n- Non-static property declarations on a `partial` class declaration cannot have initializers.\n- A `partial` class declaration can have a class decorator. User code that executes in-between the initial class declaration and the partial declaration will be able to observe the class before decorators on the `partial` class are applied.\n  - NOTE: We could choose to disallow class decorators on a `partial` class.\n# Out of scope\n- This proposal does not cover the case where built-in \"classes\" can often also be called as functions. This case is covered in #2959.\n- This proposal does not cover the case where authors may have already extended the interface of a built in. This case is covered in #2961.\n# Previous discussions\n\nThis has also been discussed previously:\n- #9 - Suggestion: Extension methods\n- #563 - Partial classes\n- https://typescript.codeplex.com/workitem/100\n","author":{"url":"https://github.com/rbuckton","@type":"Person","name":"rbuckton"},"datePublished":"2015-04-29T18:39:09Z","url":"https://github.com/microsoft/TypeScript/issues/2957"}

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:fb401b05-d135-a1f8-afe6-c9220ecafc3e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDDA4:3E4205:2110B87:2C325BE:6B018A67
html-safe-nonce24548aed27d49d54fee9638a90bec827e2e2f45d35a7d2f240d21ae35171dcd3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREE0OjNFNDIwNToyMTEwQjg3OjJDMzI1QkU6NkIwMThBNjciLCJ2aXNpdG9yX2lkIjoiOTA1NzU0NjkyMDQ2OTMwMTg2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac142b02e43a84463c0ea97ff4ea862cb2bb058159475354d9ad96b1cccd3ab8a4
hovercard-subject-tagissue:71954116
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/2957/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0a12b4e57d833c073c87b13a4be8b691993f597d7fccac2db8ade50c115ee5ab/microsoft/TypeScript/issues/2957
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0a12b4e57d833c073c87b13a4be8b691993f597d7fccac2db8ade50c115ee5ab/microsoft/TypeScript/issues/2957
og:image:altSummary To support both the semantics of subclassing built-ins in ES6 and still allow authors to augment built-ins, we need a mechanism to reopen the static and instance sides of a class. Current s...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerbuckton
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/2957#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F2957
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%2F2957
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/2957
Reloadhttps://github.com/microsoft/TypeScript/issues/2957
Reloadhttps://github.com/microsoft/TypeScript/issues/2957
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)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/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/2957
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/2957
Suggestion: Reopen static and instance side of classeshttps://github.com/microsoft/TypeScript/issues/2957#top
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/rbuckton
Ron Buckton (rbuckton)https://github.com/rbuckton
on Apr 29, 2015https://github.com/microsoft/TypeScript/issues/2957#issue-71954116
Suggestion: Merge ambient function and class declarations with the same name. #2959https://github.com/microsoft/TypeScript/issues/2959
Suggestion: Merge ambient class and interface declarations. #2961https://github.com/microsoft/TypeScript/issues/2961
Suggestion: Extension methods #9https://github.com/microsoft/TypeScript/issues/9
Partial classes  #563https://github.com/microsoft/TypeScript/issues/563
https://typescript.codeplex.com/workitem/100https://typescript.codeplex.com/workitem/100
Ron Buckton (rbuckton)https://github.com/rbuckton
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Apr 29, 2015https://github.com/microsoft/TypeScript/issues/2957#event-293302297
https://github.com/danquirk
Dan Quirk (danquirk)https://github.com/danquirk
on Apr 29, 2015https://github.com/microsoft/TypeScript/issues/2957#issuecomment-97537203
#563https://github.com/microsoft/TypeScript/issues/563
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Apr 29, 2015https://github.com/microsoft/TypeScript/issues/2957#issuecomment-97540112
#9https://github.com/microsoft/TypeScript/issues/9
https://github.com/kode4food
Thomas Bradford (kode4food)https://github.com/kode4food
on Aug 5, 2015https://github.com/microsoft/TypeScript/issues/2957#issuecomment-128025134
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Dec 9, 2015https://github.com/microsoft/TypeScript/issues/2957#event-486545661
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Apr 20, 2016https://github.com/microsoft/TypeScript/issues/2957#event-635157867
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Apr 20, 2016https://github.com/microsoft/TypeScript/issues/2957#issuecomment-212598840
https://github.com/MortenHoustonLudvigsen
Morten Houston Ludvigsen (MortenHoustonLudvigsen)https://github.com/MortenHoustonLudvigsen
on Jul 13, 2016https://github.com/microsoft/TypeScript/issues/2957#issuecomment-232386433
https://github.com/manast
Manuel Astudillo (manast)https://github.com/manast
on Aug 2, 2016https://github.com/microsoft/TypeScript/issues/2957#issuecomment-236986698
https://github.com/qwertie
David Piepgrass (qwertie)https://github.com/qwertie
on Jun 20, 2018https://github.com/microsoft/TypeScript/issues/2957#issuecomment-398920593
https://github.com/trusktr
Joe Pea (trusktr)https://github.com/trusktr
on Oct 30, 2018https://github.com/microsoft/TypeScript/issues/2957#issuecomment-434148848
https://github.com/JohnArcher
Micha J. (JohnArcher)https://github.com/JohnArcher
on Apr 4, 2019https://github.com/microsoft/TypeScript/issues/2957#issuecomment-479855676
Joe Pea (@trusktr)https://github.com/trusktr
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Nov 4, 2019https://github.com/microsoft/TypeScript/issues/2957#event-2769447787
https://github.com/saschanaz
Kagami Sascha Rosylight (saschanaz)https://github.com/saschanaz
on Nov 24, 2020https://github.com/microsoft/TypeScript/issues/2957#issuecomment-733294775
https://github.com/saschanaz
Kagami Sascha Rosylight (saschanaz)https://github.com/saschanaz
on Dec 21, 2020https://github.com/microsoft/TypeScript/issues/2957#issuecomment-749213455
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Sep 17, 2021https://github.com/microsoft/TypeScript/issues/2957#issuecomment-921900240
https://github.com/Jamesernator
James Browning (Jamesernator)https://github.com/Jamesernator
on Jan 23, 2024https://github.com/microsoft/TypeScript/issues/2957#issuecomment-1905092788
https://github.com/Jamesernator
James Browning (Jamesernator)https://github.com/Jamesernator
on May 8, 2024https://github.com/microsoft/TypeScript/issues/2957#issuecomment-2100232596
missing static methodshttps://github.com/microsoft/TypeScript/issues/58026
https://github.com/ckohen
ckohen (ckohen)https://github.com/ckohen
on Jun 24, 2024https://github.com/microsoft/TypeScript/issues/2957#issuecomment-2186170526
https://github.com/discordjs/discord.js/blob/ba0cb66ff92b0c46b020a2e471501aa4432bc978/packages/discord.js/typings/index.d.ts#L246-L258https://github.com/discordjs/discord.js/blob/ba0cb66ff92b0c46b020a2e471501aa4432bc978/packages/discord.js/typings/index.d.ts#L246-L258
@types/nodehttps://github.com/DefinitelyTyped/DefinitelyTyped/pull/68313
https://github.com/alii
Alistair Smith (alii)https://github.com/alii
on Mar 16, 2025https://github.com/microsoft/TypeScript/issues/2957#issuecomment-2727459779
microsoft/TypeScript-DOM-lib-generator#1941https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1941
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/2957
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/2957
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%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.