René's URL Explorer Experiment


Title: Allow interfaces to declare protected members and allow implementors to implement protected and private members. · Issue #3854 · microsoft/TypeScript · GitHub

Open Graph Title: Allow interfaces to declare protected members and allow implementors to implement protected and private members. · Issue #3854 · microsoft/TypeScript

X Title: Allow interfaces to declare protected members and allow implementors to implement protected and private members. · Issue #3854 · microsoft/TypeScript

Description: TL;DR: provide a syntax which kills this compiler error: Class 'D' incorrectly implements interface 'C'. Property '_a' is protected but type 'D' is not a class derived from 'C'. If the implementer wants to take responsibility for making ...

Open Graph Description: TL;DR: provide a syntax which kills this compiler error: Class 'D' incorrectly implements interface 'C'. Property '_a' is protected but type 'D' is not a class derived from 'C'. If the implementer ...

X Description: TL;DR: provide a syntax which kills this compiler error: Class 'D' incorrectly implements interface 'C'. Property '_a' is protected but type 'D' is not a class deriv...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow interfaces to declare protected members and allow implementors to implement protected and private members.","articleBody":"### TL;DR: provide a syntax which kills this compiler error:\n\n```\nClass 'D' incorrectly implements interface 'C'.\nProperty '_a' is protected but type 'D' is not a class derived from 'C'.\n```\n\nIf the implementer wants to take responsibility for making sure the private members behave correctly they should be able to do so.\n\nThis would allow mixins to have protected members and solve a few issues with other multiple inheritance use-cases.\n### Proposal: Allow implementation of protected and private members in derived and implementing classes\n\nAllow interface implementers to implement protected and private methods. This makes it possible for types with private and protected members to be implemented as interfaces (provided the inheritor correctly manages the private state).\n\nSuggested syntax:\n\n``` ts\n    class P {private _p;}\n    class Q implements P { private _p implements P; }\n```\n\nSince name mangling is not used we can't alias the private members, so if implementing more than one interface with private members, the private members must either have different names, or the underlying uses of the members must be compatible, or be made compatible.\n\n``` ts\n    class P{private _p;}\n    class P2{private _p;}\n    class Q implements P, P2{ private _p implements P, P2;}\n```\n\nOf course interfaces can have protected and private members, though they can't declare them directly and you can't implement them directly:\n\n``` ts\n    class P { protected _p = \"p\"; }\n    interface Q extends P { q; };\n    // Q can't be implemented except by a class derived from P\n    class PX extends P implements Q { q = \"q\"; }\n    class R { protected _r = \"r\"; }\n    interface S extends Q, R { s; }\n    // S cannot be implemented by anyone\n    // However you could gin up the correct members, and cast to S\n    function SFactory(): S { var px = new PX(); px[\"s\"] = \"s\"; px[\"_r\"] = \"r\"; return \u003cS>px; }\n    // you can even make it constructable:\n    class _S extends PX {\n        s = \"s\";\n        protected _r = \"r\";\n    }\n\n    var S: new (...args) => S = \u003cnew (...args) => S>\u003cnew()=> any>_S;\n    var myS = new S();\n```\n\nI understand the explanation given in #471, that we cannot simply ignore the private members, as e.g. other instances of B need to be able to access B's private members on C. However protected members are part of the API contract too, for inheritors, and we should be able to implement them. \n\nWhat's more, nothing is truly private in JavaScript. This can be achieved in typescript using the `[\"_p\"]` escape hatch and an intermediate class as above.\n### Motivation\n\nSeveral uses for this. One is that it seems to be the only way to allow mixins to have private or protected members.\n\nI'm working with a large library, and have come across the following situation, where I need a type which implements two classes/interfaces which derive from a common base. \n\nGiven these classes:\n\n``` ts\n    interface A { a; }\n    class B implements A {\n        protected _a; get a() { return this._a; }\n        BFunc() { };\n    }\n    class C implements A {\n        protected _a; get a() { return this._a; }\n        CFunc() { };\n    }\n```\n\nI need then to create a class implementing both `B` and `C`. Note that both `B` and `C` have chosen to implement `a` using a protected backing member `_a`, and that these are compatible implementations with exactly the same meaning. There is now no way to achieve this. \n\nAllowing interfaces to declare protected members would make them part of the API contract for inheritors and would solve this problem.\n\nThis does not work:\n\n``` ts\n    // Class 'D' incorrectly implements interface 'C'.\n    // Property '_a' is protected but type 'B' is not a class derived from 'C'.\n    class D extends B implements C {\n        CFunc() { };\n    }\n```\n\nNeither does this:\n\n``` ts\n    // Class 'E' incorrectly implements interface 'B'.\n    // Property '_a' is protected but type 'E' is not a class derived from 'B'.\n    // Class 'E' incorrectly implements interface 'C'.\n    // Property '_a' is protected but type 'E' is not a class derived from 'C'.   \n    class E implements B, C {\n        _a;\n        get a() { return this._a; }\n        BFunc() { };\n        CFunc() { };\n    }\n```\n\nFor example if I could reopen the interface like so: \n\n``` ts\n    interface A { protected _a;}\n```\n\nThat would solve the issue. By declaring it part of the API contract, albeit one only accessible to inheritors, we solve the problem.\n\nCurrently the only way to work around involves making the backing member public in the interface, or public in the derived classes. (There has to be a backing member in this case). Even making the `A` a class, and declaring the protected member won't allow you to do it.\n","author":{"url":"https://github.com/benliddicott","@type":"Person","name":"benliddicott"},"datePublished":"2015-07-14T16:39:01Z","url":"https://github.com/microsoft/TypeScript/issues/3854"}

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:c39d21a2-11ec-32b1-a783-9ce8e9723118
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE2C8:A7C8F:94F002:C13BB4:6B00DE32
html-safe-noncec5135cdb7f7663da8248eed03bd142fef280200e42ce5a13b1b4b11d3bc95870
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkM4OkE3QzhGOjk0RjAwMjpDMTNCQjQ6NkIwMERFMzIiLCJ2aXNpdG9yX2lkIjoiNzE1NTE4Njg3MDA1MjI0OTEzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1c917ec5db1d7bb95a8738b2cb9a0c5116840aea2359788ca0df22ccb86ebfc7
hovercard-subject-tagissue:94986425
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/3854/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6b20f15b3a1490eb11d03ac1983e7f765ab5548b6187ef82a325b85208bfe764/microsoft/TypeScript/issues/3854
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6b20f15b3a1490eb11d03ac1983e7f765ab5548b6187ef82a325b85208bfe764/microsoft/TypeScript/issues/3854
og:image:altTL;DR: provide a syntax which kills this compiler error: Class 'D' incorrectly implements interface 'C'. Property '_a' is protected but type 'D' is not a class derived from 'C'. If the implementer ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebenliddicott
hostnamegithub.com
expected-hostnamegithub.com
None043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf
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
release5425dc24e8bd8d6fca9641a12afc984825a43875
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/3854#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F3854
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%2F3854
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/3854
Reloadhttps://github.com/microsoft/TypeScript/issues/3854
Reloadhttps://github.com/microsoft/TypeScript/issues/3854
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests308 (308)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/3854
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/3854
Allow interfaces to declare protected members and allow implementors to implement protected and private members.https://github.com/microsoft/TypeScript/issues/3854#top
DeclinedThe issue was declined as something which matches the TypeScript visionhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Declined%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/benliddicott
benliddicotthttps://github.com/benliddicott
on Jul 14, 2015https://github.com/microsoft/TypeScript/issues/3854#issue-94986425
#471https://github.com/microsoft/TypeScript/issues/471
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Aug 10, 2015https://github.com/microsoft/TypeScript/issues/3854#event-378453724
https://github.com/benliddicott
benliddicotthttps://github.com/benliddicott
on Aug 11, 2015https://github.com/microsoft/TypeScript/issues/3854#issuecomment-130025573
#4278https://github.com/microsoft/TypeScript/issues/4278
#4278https://github.com/microsoft/TypeScript/issues/4278
https://github.com/benliddicott
benliddicotthttps://github.com/benliddicott
on Aug 14, 2015https://github.com/microsoft/TypeScript/issues/3854#issuecomment-131097843
#471https://github.com/microsoft/TypeScript/issues/471
https://github.com/TheAifam5
Mateusz Paluszkiewicz (TheAifam5)https://github.com/TheAifam5
on Aug 4, 2016https://github.com/microsoft/TypeScript/issues/3854#issuecomment-237412076
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Aug 4, 2016https://github.com/microsoft/TypeScript/issues/3854#issuecomment-237438182
Mateusz Paluszkiewicz (@TheAifam5)https://github.com/TheAifam5
https://github.com/mp3por
Velin Kerkov (mp3por)https://github.com/mp3por
on Jan 20, 2017https://github.com/microsoft/TypeScript/issues/3854#issuecomment-274084853
https://github.com/seedy
Seedy (seedy)https://github.com/seedy
on Dec 1, 2017https://github.com/microsoft/TypeScript/issues/3854#issuecomment-348480344
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Dec 1, 2017https://github.com/microsoft/TypeScript/issues/3854#issuecomment-348559309
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
DeclinedThe issue was declined as something which matches the TypeScript visionhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Declined%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Dec 1, 2017https://github.com/microsoft/TypeScript/issues/3854#event-1368092428
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Dec 1, 2017https://github.com/microsoft/TypeScript/issues/3854#event-1368092556
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/3854#event-1689605957
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/3854
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/3854
DeclinedThe issue was declined as something which matches the TypeScript visionhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Declined%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.