René's URL Explorer Experiment


Title: Suggestion: Upper-bound generic type constraints · Issue #9252 · microsoft/TypeScript · GitHub

Open Graph Title: Suggestion: Upper-bound generic type constraints · Issue #9252 · microsoft/TypeScript

X Title: Suggestion: Upper-bound generic type constraints · Issue #9252 · microsoft/TypeScript

Description: This is a proposal for generic structural supertype constraints. I'll first detail the proposal, and then get into a discussion about use-cases. Proposal A supertype constraint is a constraint on a generic type parameter to be the struct...

Open Graph Description: This is a proposal for generic structural supertype constraints. I'll first detail the proposal, and then get into a discussion about use-cases. Proposal A supertype constraint is a constraint on a...

X Description: This is a proposal for generic structural supertype constraints. I'll first detail the proposal, and then get into a discussion about use-cases. Proposal A supertype constraint is a constraint ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: Upper-bound generic type constraints","articleBody":"This is a proposal for generic structural supertype constraints.\n\nI'll first detail the proposal, and then get into a discussion about use-cases.\n## Proposal\n\nA supertype constraint is a constraint on a generic type parameter to be the structural _supertype_ of another type. It's like a subtype/inheritance constraint, but from the other direction. For example, let's say we have a square:\n\n```\ninterface Square {width : number; height : number}\n```\n\nIn this suggested syntax, you could write:\n\n```\nperformAction\u003cT extended by Square>(partialSquare : T) {}\n```\n\nThis means the type `T` must be a structural supertype of square. So the potential candidates for `T` are:\n\n```\n{width : number}, {height : number}, Square, {}\n```\n\nIt's an established kind of type constraint, not something I just made up. Although it's not exactly common, some languages do implement this feature, such as Scala. In Scala, you can write:\n\n```\ndef performAction[T >: Square](obj : T) = { ... }\n```\n\nTo express a supertype/upper bound constraint. In this case, of course, the constraint isn't structural -- `T` must declare that it implements `Square`. \n## Utility\n\nIn most languages, including Scala, this kind of constraint isn't very useful. It only comes up in certain specific situations. \n\nHowever, Javascript libraries often have this kind of API, where you're allowed to specify the partial properties of an object to modify it (the rest remain at their previous value).\n\nIn many cases, you can support this by having optional interface members, but isn't always possible or correct.\n\nAn important example is React, which defines a method called `setState`:\n\n```\nclass Component {\n    var state;\n\n    setState(partialState) {\n        //merges the properties of partialState with the current state.\n    }\n}\n```\n\nThe right signature for this method should be:\n\n```\nclass Component\u003cProps, State> {\n    setState\u003cPartialState extended by State>(partialState : PartialState) {\n        //merges the properties of partialState with the current state.\n    }\n}\n```\n\nCurrently,the definition files state that it is:\n\n```\nsetState(fullState : State) {\n    //merges the properties of partialState with the current state.\n}\n```\n\nWhich doesn't fully capture the functionality of the method.\n## Notes\n\nThe suggested syntax doesn't give us a nice way of combining both subtype and supertype constraints. One possibility is:\n\n```\nexampleMethod\u003cT extends LowerBound and extended by UpperBound>\n```\n","author":{"url":"https://github.com/GregRos","@type":"Person","name":"GregRos"},"datePublished":"2016-06-19T09:38:42Z","url":"https://github.com/microsoft/TypeScript/issues/9252"}

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:6bb251bf-c782-acb2-904f-2eeaba8e38fb
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC86E:17CCC0:DDDB5:13673D:6AFBDB0E
html-safe-nonceff0d61e5bc698a2751aca4a70fb898cedd4e9f867800b4dc602efaf110646df0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODZFOjE3Q0NDMDpERERCNToxMzY3M0Q6NkFGQkRCMEUiLCJ2aXNpdG9yX2lkIjoiMTI5OTU2MjgzMTAzMjM0MzMxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacab5dac331b4a1d9c9607b10abbe38c1d0904bdc4bf3b0b09f748e49c6bcb4560
hovercard-subject-tagissue:161064954
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/9252/issue_layout
twitter:imagehttps://opengraph.githubassets.com/75348e33c8bf354ac1667a8a7533625c43ae4b45eebe55c6ee2a1fd0894af7b9/microsoft/TypeScript/issues/9252
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/75348e33c8bf354ac1667a8a7533625c43ae4b45eebe55c6ee2a1fd0894af7b9/microsoft/TypeScript/issues/9252
og:image:altThis is a proposal for generic structural supertype constraints. I'll first detail the proposal, and then get into a discussion about use-cases. Proposal A supertype constraint is a constraint on a...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameGregRos
hostnamegithub.com
expected-hostnamegithub.com
None18742cb872ec73544356e60359266b67aafece70c4ce008042e06227924cdd07
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
release820be804f18e1ef3940bd74a00d41d73d02e2b91
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/9252#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F9252
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%2F9252
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/9252
Reloadhttps://github.com/microsoft/TypeScript/issues/9252
Reloadhttps://github.com/microsoft/TypeScript/issues/9252
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/9252
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9252
Suggestion: Upper-bound generic type constraintshttps://github.com/microsoft/TypeScript/issues/9252#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/GregRos
Greg Ros (GregRos)https://github.com/GregRos
on Jun 19, 2016https://github.com/microsoft/TypeScript/issues/9252#issue-161064954
https://github.com/Strate
Artur Eshenbrener (Strate)https://github.com/Strate
on Jun 19, 2016https://github.com/microsoft/TypeScript/issues/9252#issuecomment-227000022
#4889https://github.com/microsoft/TypeScript/issues/4889
#371https://github.com/microsoft/TypeScript/issues/371
https://github.com/GregRos
Greg Ros (GregRos)https://github.com/GregRos
on Jun 20, 2016https://github.com/microsoft/TypeScript/issues/9252#issuecomment-227146194
Artur Eshenbrener (@Strate)https://github.com/Strate
https://github.com/Strate
Artur Eshenbrener (Strate)https://github.com/Strate
on Jun 20, 2016https://github.com/microsoft/TypeScript/issues/9252#issuecomment-227152757
Greg Ros (@GregRos)https://github.com/GregRos
#4889https://github.com/microsoft/TypeScript/issues/4889
this commenthttps://github.com/Microsoft/TypeScript/issues/4889#issuecomment-200388292
thathttps://github.com/Microsoft/TypeScript/issues/4889#issuecomment-200745084
https://github.com/GregRos
Greg Ros (GregRos)https://github.com/GregRos
on Jun 20, 2016https://github.com/microsoft/TypeScript/issues/9252#issuecomment-227155858
Open Source Projects from State (@State)https://github.com/State
#4889https://github.com/microsoft/TypeScript/issues/4889
#371https://github.com/microsoft/TypeScript/issues/371
#4889https://github.com/microsoft/TypeScript/issues/4889
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Oct 10, 2016https://github.com/microsoft/TypeScript/issues/9252#issuecomment-252775216
#11233https://github.com/microsoft/TypeScript/issues/11233
#4889https://github.com/microsoft/TypeScript/issues/4889
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
on Oct 10, 2016https://github.com/microsoft/TypeScript/issues/9252#event-818768780
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Feb 21, 2017https://github.com/microsoft/TypeScript/issues/9252#event-971600857
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/9252#event-1689839944
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
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
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
on Oct 9, 2018https://github.com/microsoft/TypeScript/issues/9252#event-1893577388
microsofthttps://github.com/microsoft
on Oct 9, 2018https://github.com/microsoft/TypeScript/issues/9252#event-1893577694
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 9, 2018https://github.com/microsoft/TypeScript/issues/9252#event-1893577846
https://github.com/timsuchanek
Tim Suchanek (timsuchanek)https://github.com/timsuchanek
on Mar 14, 2019https://github.com/microsoft/TypeScript/issues/9252#issuecomment-472881853
Greg Ros (@GregRos)https://github.com/GregRos
https://github.com/laurensdijkstra
laurensdijkstrahttps://github.com/laurensdijkstra
on May 11, 2019https://github.com/microsoft/TypeScript/issues/9252#issuecomment-491502235
#11233https://github.com/microsoft/TypeScript/issues/11233
#4889https://github.com/microsoft/TypeScript/issues/4889
Greg Ros (@GregRos)https://github.com/GregRos
https://github.com/truemogician
0x269 (truemogician)https://github.com/truemogician
on Nov 6, 2022https://github.com/microsoft/TypeScript/issues/9252#issuecomment-1304734793
Greg Ros (@GregRos)https://github.com/GregRos
#4196https://github.com/microsoft/TypeScript/issues/4196
#4196https://github.com/microsoft/TypeScript/issues/4196
https://github.com/graphemecluster
graphemecluster (graphemecluster)https://github.com/graphemecluster
on Mar 12, 2023https://github.com/microsoft/TypeScript/issues/9252#issuecomment-1465199836
#14520https://github.com/microsoft/TypeScript/issues/14520
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/9252
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9252
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.