René's URL Explorer Experiment


Title: TS Proposal : "Interface incorrectly extends interface" - sub-interface method overload OR override ? · Issue #20920 · microsoft/TypeScript · GitHub

Open Graph Title: TS Proposal : "Interface incorrectly extends interface" - sub-interface method overload OR override ? · Issue #20920 · microsoft/TypeScript

X Title: TS Proposal : "Interface incorrectly extends interface" - sub-interface method overload OR override ? · Issue #20920 · microsoft/TypeScript

Description: TypeScript Version : 2.6.2 The problem Initial scenario I encountered the issue yesterday days as I was trying to add some features to one of my interface inheritance chain. The context of this example is just imagined : It is longer tha...

Open Graph Description: TypeScript Version : 2.6.2 The problem Initial scenario I encountered the issue yesterday days as I was trying to add some features to one of my interface inheritance chain. The context of this exa...

X Description: TypeScript Version : 2.6.2 The problem Initial scenario I encountered the issue yesterday days as I was trying to add some features to one of my interface inheritance chain. The context of this exa...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS Proposal : \"Interface incorrectly extends interface\" - sub-interface method overload OR override ?","articleBody":"**TypeScript Version :**  2.6.2\r\n\r\n## The problem\r\n\r\n**Initial scenario**\r\n\r\nI encountered the issue yesterday days as I was trying to add some features to one of my interface inheritance chain. The context of this example is just imagined : It is longer than needed to demonstrate the issue, but I wanted a full example to clearly show it needs to be addressed.\r\n\r\nSo, let's imagine a testing app that should instrument devices : the following is a potential model of the situation :\r\n\r\n```ts\r\ninterface Stream\r\n{\r\n}\r\ninterface InputStream\r\n{\r\n}\r\ninterface OutputStream\r\n{\r\n}\r\n// interface inheraitance is a great feature\r\ninterface IOStream extends InputStream, OutputStream\r\n{\r\n}\r\n```\r\n\r\n```ts\r\ninterface InterfaceLike\r\n{\r\n}\r\ninterface DeviceInterfaceLike extends InterfaceLike\r\n{\r\n    init();\r\n}\r\ninterface InputDeviceInterfaceLike extends DeviceInterfaceLike\r\n{\r\n    input(); // this should word just like the `touch` command\r\n             //     like if there's and error with the device, it will trigger exception\r\n    input(stream: InputStream);\r\n}\r\n```\r\n\r\n```ts\r\ninterface ScreenDeviceInterfaceLike extends InputDeviceInterfaceLike\r\n{\r\n    input(stream: InputStream, coordinates: {x: number, y: number});\r\n}\r\ninterface TouchScreenDeviceInterfaceLike extends InputDeviceInterfaceLike\r\n{\r\n    input(stream: IOStream, coordinates: {x: number, y: number});\r\n}\r\n```\r\n\r\n**Expected behavior :**\r\n\r\nIt should just overload that method in the sub-interfaces.\r\n\r\n**Actual behavior :**\r\n\r\n```\r\nerror TS2430: Interface 'ScreenDeviceInterfaceLike' incorrectly extends interface 'InputDeviceInterfaceLike'.\r\n  Types of property 'input' are incompatible.\r\n    Type '(stream: InputStream, coordinates: { x: number; y: number; }) => any' is not assignable to type '{ (): any; (stream: InputStream): any; }'.\r\ncore.ts(73,11): error TS2430: Interface 'TouchScreenDeviceInterfaceLike' incorrectly extends interface 'InputDeviceInterfaceLike'.\r\n  Types of property 'input' are incompatible.\r\n    Type '(stream: IOStream, coordinates: { x: number; y: number; }) => any' is not assignable to type '{ (): any; (stream: InputStream): any; }'.\r\n18:38:26 - Compilation complete. Watching for file changes.\r\n```\r\n\r\nIt requires me to fully copy paste all method signatures in each interface.\r\n\r\n```ts\r\ninterface ScreenDeviceInterfaceLike extends InputDeviceInterfaceLike\r\n{\r\n    input(); // this should word just like the `touch` command\r\n             //     like if there's and error with the device, it will trigger exception\r\n    input(stream: InputStream);\r\n    input(stream: InputStream, coordinates: {x: number, y: number});\r\n}\r\ninterface TouchScreenDeviceInterfaceLike extends InputDeviceInterfaceLike\r\n{\r\n    input(); // this should word just like the `touch` command\r\n             //     like if there's and error with the device, it will trigger exception\r\n    input(stream: InputStream);\r\n    input(stream: IOStream, coordinates: {x: number, y: number});\r\n} \r\n```\r\n\r\nWhen you're can have up to (why not) 15 overloads distributed through inheritance chain... It becomes, (yes, you said it) bulky.\r\n\r\n-----\r\n\r\nNow it is, that the compiler cannot yet figure out when to `override` the method signatures inherited from parents and when to `overload` them.\r\n\r\n## The Proposal\r\n\r\nMy first thought was to introduce a new keyword just like `@ts-nocheck` and like.\r\n\r\n### `@override`\r\n\r\n```ts\r\ninterface InputDeviceInterfaceLike extends DeviceInterfaceLike\r\n{\r\n    @override // to override all definitions from parents\r\n    init(istream: InputStream);\r\n}\r\n```\r\nOR\r\n```ts\r\ninterface InputDeviceInterfaceLike extends DeviceInterfaceLike\r\n{\r\n    @override\r\n    {\r\n        init(); // to override only this (these) definitions : forget all previous definition but this (these)\r\n    }\r\n    init(istream: InputStream);\r\n}\r\n```\r\n\r\nThen, the `TouchScreenDeviceInterfaceLike` interface would become :\r\n\r\n```ts\r\ninterface TouchScreenDeviceInterfaceLike extends InputDeviceInterfaceLike\r\n{\r\n    @override   // it is now clear that the only way to instrument a touchscreen is to provide a `IOStream` and coordinates (`{x: number, y: number}`)\r\n    input(stream: IOStream, coordinates: {x: number, y: number});\r\n}\r\n```\r\n\r\n### Furthermore, `@overload`\r\n\r\nWhile the previous **`@override` is useful when the default behavior is oveloading**, we can still define the default behavior to **suppress all parent definition WHEN A METHOD IS REDEFINED in subinterface, except when `@overload` is used**. i.e\r\n\r\n```ts\r\ninterface InputDeviceInterfaceLike extends DeviceInterfaceLike\r\n{\r\n    // to override all definitions from parents\r\n    init(istream: InputStream);\r\n}\r\n```\r\n\r\nOR\r\n\r\n```ts\r\ninterface InputDeviceInterfaceLike extends DeviceInterfaceLike\r\n{\r\n    @overload // to overload signatures from parents\r\n    init(istream: InputStream);\r\n}\r\n```\r\n\r\nAnd `TouchScreenDeviceInterfaceLike` interface can become :\r\n\r\n```ts\r\ninterface TouchScreenDeviceInterfaceLike extends InputDeviceInterfaceLike\r\n{\r\n    @overload                           // to overload signatures from parents\r\n    {\r\n        init(istream: InputStream);     //      except this signature... So that it remains only the empty parameter and the below\r\n    }\r\n    input(stream: IOStream, coordinates: {x: number, y: number});\r\n}\r\n```\r\n\r\n----\r\n\r\nBy thinking rigorously, I think the first step would be allow inheriting type to overload methods by default.\r\n\r\n**= = = = = = UPDATE = = = = = =**\r\nI now think it worth to add that by no mean, all through an interface inheritance chain should a method be completely wiped off (deleted, removed)... Not even by `@Override`! As this may (will) break the core concept of OOP inheritance.\r\n\r\nThe mechanism is to ensure that only some methods mood (signatures) are handled (accepted) at a given inheritance node.\r\n\r\nIn other words, if `@Override` suppresses all signatures, at least one method signature MUST be required.","author":{"url":"https://github.com/SalathielGenese","@type":"Person","name":"SalathielGenese"},"datePublished":"2017-12-28T17:45:53Z","url":"https://github.com/microsoft/TypeScript/issues/20920"}

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:22227f69-43d6-a373-7368-eda146e107ac
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id82E4:129351:1CF0BF1:2522143:6B03CCE0
html-safe-nonceee4734051e5b26dba855d017b8bd8aabfd3727d762c3c2f355c4c0ef8020ca7c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkU0OjEyOTM1MToxQ0YwQkYxOjI1MjIxNDM6NkIwM0NDRTAiLCJ2aXNpdG9yX2lkIjoiODE4NTM1OTkwNTg1MTY5MDIwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb2cade1c7fa7b8de104c35918e1f57f42ef57d040c878ae4a8257646aba0c8ab
hovercard-subject-tagissue:284960285
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/20920/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f1ee55cf912eef21c662c0ac5bb983be50630fe2229eaed081c5c8d147f9fb1d/microsoft/TypeScript/issues/20920
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f1ee55cf912eef21c662c0ac5bb983be50630fe2229eaed081c5c8d147f9fb1d/microsoft/TypeScript/issues/20920
og:image:altTypeScript Version : 2.6.2 The problem Initial scenario I encountered the issue yesterday days as I was trying to add some features to one of my interface inheritance chain. The context of this exa...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSalathielGenese
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/20920#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F20920
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%2F20920
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/20920
Reloadhttps://github.com/microsoft/TypeScript/issues/20920
Reloadhttps://github.com/microsoft/TypeScript/issues/20920
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests319 (319)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/20920
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/20920
TS Proposal : "Interface incorrectly extends interface" - sub-interface method overload OR override ?https://github.com/microsoft/TypeScript/issues/20920#top
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
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/SalathielGenese
Salathiel Genese (SalathielGenese)https://github.com/SalathielGenese
on Dec 28, 2017https://github.com/microsoft/TypeScript/issues/20920#issue-284960285
Salathiel Genese (SalathielGenese)https://github.com/SalathielGenese
on Dec 30, 2017https://github.com/microsoft/TypeScript/issues/20920#event-1404991707
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Jan 4, 2018https://github.com/microsoft/TypeScript/issues/20920#event-1410246934
https://github.com/shobhitg
Shobhit Gupta (shobhitg)https://github.com/shobhitg
on Feb 1, 2018https://github.com/microsoft/TypeScript/issues/20920#issuecomment-362408962
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Feb 5, 2018https://github.com/microsoft/TypeScript/issues/20920#issuecomment-363185603
https://github.com/shobhitg
Shobhit Gupta (shobhitg)https://github.com/shobhitg
on Feb 5, 2018https://github.com/microsoft/TypeScript/issues/20920#issuecomment-363223823
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
https://github.com/SalathielGenese
Salathiel Genese (SalathielGenese)https://github.com/SalathielGenese
on Feb 5, 2018https://github.com/microsoft/TypeScript/issues/20920#issuecomment-363251526
https://github.com/SalathielGenese
Salathiel Genese (SalathielGenese)https://github.com/SalathielGenese
on Feb 6, 2018https://github.com/microsoft/TypeScript/issues/20920#issuecomment-363397339
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
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 Feb 6, 2018https://github.com/microsoft/TypeScript/issues/20920#event-1460689086
https://github.com/SephReed
Seph Reed (SephReed)https://github.com/SephReed
on Jul 20, 2018https://github.com/microsoft/TypeScript/issues/20920#issuecomment-406700139
https://github.com/zhengxiaoyao0716
Water Zheng (zhengxiaoyao0716)https://github.com/zhengxiaoyao0716
on May 29, 2019https://github.com/microsoft/TypeScript/issues/20920#issuecomment-496819809
https://user-images.githubusercontent.com/12682063/58537729-0d98da00-8226-11e9-8d3d-1ee66cb5282f.png
https://user-images.githubusercontent.com/12682063/58537798-37520100-8226-11e9-827d-7609a686cd9e.png
https://user-images.githubusercontent.com/12682063/58537833-5355a280-8226-11e9-85e5-69ee69ca3d11.png
https://user-images.githubusercontent.com/12682063/58537882-74b68e80-8226-11e9-9439-976575e2d40d.png
https://user-images.githubusercontent.com/12682063/58537897-8009ba00-8226-11e9-9ce9-4ddd01611229.png
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/20920
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/20920
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
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

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.