René's URL Explorer Experiment


Title: Proposal: Introduce a new way to define "inherited" interfaces: likes · Issue #18762 · microsoft/TypeScript · GitHub

Open Graph Title: Proposal: Introduce a new way to define "inherited" interfaces: likes · Issue #18762 · microsoft/TypeScript

X Title: Proposal: Introduce a new way to define "inherited" interfaces: likes · Issue #18762 · microsoft/TypeScript

Description: If anyone has interest in this proposal, please let me know, I may do more future work (like try to implement it) Sometimes, we need a way to introduce an interface that is incompatible with original type but very likes to the original t...

Open Graph Description: If anyone has interest in this proposal, please let me know, I may do more future work (like try to implement it) Sometimes, we need a way to introduce an interface that is incompatible with origin...

X Description: If anyone has interest in this proposal, please let me know, I may do more future work (like try to implement it) Sometimes, we need a way to introduce an interface that is incompatible with origin...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Introduce a new way to define \"inherited\" interfaces: likes","articleBody":"If anyone has interest in this proposal, please let me know, I may do more future work (like try to implement it)\r\n\r\nSometimes, we need a way to introduce an interface that is incompatible with original type but very likes to the original type.\r\n\r\n\r\n\r\nFor example, in node-canvas package, they provide a class `Canvas` that very likes to the `HTMLCanvasElement`, but it **is not** compatible with `HTMLCanvasElement`. If we can have a clear way to \"clone\" an interface and make some changes, we can just use this way instead of copy-paste everything in the original type.\r\n\r\n\r\n\r\n## Proposal: Introduce a new way to define \"inherited\" interfaces: `likes`\r\n\r\n```typescript\r\n\r\ninterface A { name: string, id: number }\r\n\r\ninterface B likes A { id: typeof uuid }\r\n\r\ninterface C likes B, A extends X {}\r\n```\r\n\r\n### Changes to the grammar\r\n\r\nChange `InterfaceDeclaration` to:\r\n\r\n*interface* ‎BindingIdentifier ‎TypeParameters(opt) ‎**InterfaceLikesClause(opt)** ‎InterfaceExtendsClause (opt) ‎ObjectType\r\n\r\n\r\nAdd `InterfaceLikesClause`:\r\n*likes* ClassOrInterfaceTypeList\r\n\r\n## Why to introduce this?\r\n1. It provides a more clear way to write two very similar (but not identical) interface.\r\n2. ‎Developers can know what different between this interface and what it's liking. (Oh, only property `name` is incompatible with `Person`, I can treat it as a little different type of `Person`)\r\n3. ‎If a change was made in the original type, it will automatically appear in the liking interface.\r\n\r\n## Why not to introduce this?\r\n1. This proposal introduced a new keyword `likes`\r\n2. ‎This CFG is some bit of ambiguous about if `likes` is a variable name or a keyword.\r\n3. ‎Maybe this scenario is not common enough to introduce a new feature to it.\r\n\r\n## When to use it\r\n1. Only a few properties are different from another one, and they have **no logically inherited relationship**.\r\n2. ‎If you cannot modify the parent interface (like `HTMLCanvasElement`) but you really want to \"extends\" from it.\r\n\r\n## When not to use it\r\n1. Only a few properties are needed from another interface. ( Just use `ISth['name']` )\r\n2. You do not want to let other new properties automatically appear. ( Like you do not need new attributes on `HTMLElement` also appears on your `FakeElement`, you need a copy-paste )\r\n3. You can modify both `A` and `B` and they have logically inherited(or whatever) relationship. ( You should find something common, make it into `C`, and let `A` and `B` extends from `C` )\r\n4. The new interface is compatible with the original type. ( Just use `extends` )\r\n\r\n## Way to generate new type\r\n**Need to be precise**\r\n1. After we finished dealing with extends, we get interface _extended\r\n2. ‎Do all the same things just like extends **expect** one thing: **Inherited properties with the same name must be identical (section 3.11.2).** (In typescript spec, 7.1), that means this is a conflict friendly version of interface extends.\r\nNow we get interface _extended_liked_\r\n3. Read all types in ObjectType, merge it into _extended_liked_\r\n4. ‎We now get the final interface\r\n\r\n## Deal with confliction\r\n\r\n```typescript\r\ninterface _ likes A, B, ... extends C, D, ... { ...E }\r\n```\r\n\r\n1. If anything with the same name is not compatible in C and D, throw an Error ( Property X in C and D are not compatible )\r\n2. ‎If anything with the same name is not compatible in A and C (or B and D, and so on), use declaration in C (or D)\r\n3.a ‎If anything with the same name is not compatible in A and B, check if it is defined in E, if not, throw an Error ( Property X in C and D is not compatible and also not defined in the interface body, cannot determine which one to use )\r\n3.b If anything with the same name is not compatible in A and B, make this property as type `A.X | B.X`\r\n3. 3.a or 3.b, which one is better?\r\n4. ‎If anything with the same name is not compatible in E and C, throw an Error ( Property X in the interface body are not compatible with X defined in C )\r\n5. ‎If anything with the same name is not compatible with E and A, use that in E\r\n\r\nFor example: \r\n\r\n2.\r\n```typescript\r\ninterface Foreigner { name: string, id: number }\r\ninterface Student { id: typeof uuid }\r\ninterface ForeignerStudent likes Foreigner extends Student {  }\r\n\r\n// ForeignerStudent is a subtype of Student, but not a sub-type of Foreigner\r\n// ForeignerStudent = { name: string, id: typeof uuid }\r\n```\r\n\r\n3.a\r\n```typescript\r\ninterface Foreigner { name: string, id: number }\r\ninterface Student { id: typeof uuid }\r\ninterface ForeignerStudent likes Foreigner, Student {  }\r\n// Error: Property id is not compatible\r\n//     typeof uuid is not compatible with number\r\n//          You need to specify a type for id\r\ninterface ForeignerStudent2 likes Foreigner, Student { id: typeof uuid }\r\n// This is fine.\r\n```\r\n\r\n3.b\r\n```typescript\r\ninterface Foreigner { name: string, id: number }\r\ninterface Student { id: typeof uuid }\r\ninterface ForeignerStudent likes Foreigner, Student {  }\r\n// ForeignerStudent = { name: string, id: number | typeof uuid }\r\n```\r\n\r\n## Others\r\n\r\n**What if I want to remove a property inherited by `likes`?**\r\nI have 2 ideas at present\r\n```typescript\r\ninterface N likes M {\r\n    y: never // this way\r\n    ‎delete x // or this way\r\n}\r\n```\r\nIf anyone has interest in this proposal, I will consider it later.\r\n\r\n**When will a liked interface compatible with the original interface?**\r\nJust treat it as an another identical normal interface.\r\n\r\n**Does it breaks the type system?**\r\nI don't think so. It is *not* a subtype of the original type.\r\n\r\n**What about generics work with proposal?**\r\nNo idea, I will think it later.","author":{"url":"https://github.com/Jack-Works","@type":"Person","name":"Jack-Works"},"datePublished":"2017-09-26T09:31:29Z","url":"https://github.com/microsoft/TypeScript/issues/18762"}

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:d5651603-3017-c88b-76cd-5ab5a38152ee
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9ABA:C2718:6B0FBB:8C7BA5:6B00D482
html-safe-nonce0023d7d41fa02a9a47fd45bb74b72825484fd5720539b9e4942ecb5b266b2957
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUJBOkMyNzE4OjZCMEZCQjo4QzdCQTU6NkIwMEQ0ODIiLCJ2aXNpdG9yX2lkIjoiNDU0ODQ3Njc2NzQ4NDA0MDMyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1ea66052360300383473973278e0e4ae0579efa95c6244e266a45aaaa37b534d
hovercard-subject-tagissue:260555330
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/18762/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7f33baaf23a3f33f45eb40ae46b8d05a3b86580dca252437a35b6f3211afb2c2/microsoft/TypeScript/issues/18762
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7f33baaf23a3f33f45eb40ae46b8d05a3b86580dca252437a35b6f3211afb2c2/microsoft/TypeScript/issues/18762
og:image:altIf anyone has interest in this proposal, please let me know, I may do more future work (like try to implement it) Sometimes, we need a way to introduce an interface that is incompatible with origin...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJack-Works
hostnamegithub.com
expected-hostnamegithub.com
None85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5
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
release4943239a6d2c591325dad6e5c313e1cafda877f6
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/18762#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F18762
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%2F18762
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/18762
Reloadhttps://github.com/microsoft/TypeScript/issues/18762
Reloadhttps://github.com/microsoft/TypeScript/issues/18762
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests307 (307)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/18762
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/18762
Proposal: Introduce a new way to define "inherited" interfaces: likeshttps://github.com/microsoft/TypeScript/issues/18762#top
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/Jack-Works
Jack Works (Jack-Works)https://github.com/Jack-Works
on Sep 26, 2017https://github.com/microsoft/TypeScript/issues/18762#issue-260555330
https://github.com/kitsonk
Kitson Kelly (kitsonk)https://github.com/kitsonk
on Sep 26, 2017https://github.com/microsoft/TypeScript/issues/18762#issuecomment-332143434
https://github.com/Jack-Works
Jack Works (Jack-Works)https://github.com/Jack-Works
on Sep 26, 2017https://github.com/microsoft/TypeScript/issues/18762#issuecomment-332145538
https://github.com/kitsonk
Kitson Kelly (kitsonk)https://github.com/kitsonk
on Sep 26, 2017https://github.com/microsoft/TypeScript/issues/18762#issuecomment-332161286
https://github.com/Jack-Works
Jack Works (Jack-Works)https://github.com/Jack-Works
on Sep 26, 2017https://github.com/microsoft/TypeScript/issues/18762#issuecomment-332196741
…https://github.com/microsoft/TypeScript/issues/18762
#18762 (comment)https://github.com/microsoft/TypeScript/issues/18762#issuecomment-332161286
https://github.com/notifications/unsubscribe-auth/AFJBfzUIzk2bXoaOmogxCoULafK6HoJtks5smNepgaJpZM4Pj8q5https://github.com/notifications/unsubscribe-auth/AFJBfzUIzk2bXoaOmogxCoULafK6HoJtks5smNepgaJpZM4Pj8q5
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Sep 26, 2017https://github.com/microsoft/TypeScript/issues/18762#event-1266304248
https://github.com/Jack-Works
Jack Works (Jack-Works)https://github.com/Jack-Works
on Oct 25, 2017https://github.com/microsoft/TypeScript/issues/18762#issuecomment-339183600
#10727https://github.com/microsoft/TypeScript/issues/10727
https://github.com/HerringtonDarkholme
Herrington Darkholme (HerringtonDarkholme)https://github.com/HerringtonDarkholme
on Feb 8, 2018https://github.com/microsoft/TypeScript/issues/18762#issuecomment-364075667
#21316https://github.com/microsoft/TypeScript/pull/21316
#13604https://github.com/microsoft/TypeScript/pull/13604
https://github.com/Jack-Works
Jack Works (Jack-Works)https://github.com/Jack-Works
on Feb 8, 2018https://github.com/microsoft/TypeScript/issues/18762#issuecomment-364077373
#10727https://github.com/microsoft/TypeScript/issues/10727
Jack Works (Jack-Works)https://github.com/Jack-Works
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Feb 8, 2018https://github.com/microsoft/TypeScript/issues/18762#event-1464316347
microsofthttps://github.com/microsoft
on Jul 3, 2018https://github.com/microsoft/TypeScript/issues/18762#event-1712802713
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/18762
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/18762
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%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.