René's URL Explorer Experiment


Title: More accurate typing of Object.assign and React component setState() · Issue #6613 · microsoft/TypeScript · GitHub

Open Graph Title: More accurate typing of Object.assign and React component setState() · Issue #6613 · microsoft/TypeScript

X Title: More accurate typing of Object.assign and React component setState() · Issue #6613 · microsoft/TypeScript

Description: This is a proposal for solving the second use case mentioned in Issue #6218 Problem /** * This class is a given by the React framework */ class ReactComponent { protected _state: S; /** * This method actually accepts any supertype of ...

Open Graph Description: This is a proposal for solving the second use case mentioned in Issue #6218 Problem /** * This class is a given by the React framework */ class ReactComponent { protected _state: S; /** * This m...

X Description: This is a proposal for solving the second use case mentioned in Issue #6218 Problem /** * This class is a given by the React framework */ class ReactComponent<S> { protected _state: S; /** * ...

Mail addresses
notifications@github.com

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"More accurate typing of Object.assign and React component setState()","articleBody":"This is a proposal for solving the second use case mentioned in Issue #6218\n## Problem\n\n``` javascript\n\n/**\n * This class is a given by the React framework\n */\nclass ReactComponent\u003cS> {\n    protected _state: S;\n\n    /**\n     * This method actually accepts any supertype of S\n     */\n    protected setState(newState: S): void {\n        for (let name in newState) {\n            if (newState.hasOwnProperty(name)) {\n                this._state[name] = newState[name];\n            }\n        }\n    }\n\n    protected componentWillMount(): void {\n        // abstract\n    }\n}\n\n/**\n * Some state interface declaration. Note all members are optional to allow setState to\n * be called with supertypes of BaseState\n */\ninterface BaseState {\n    a?: string;\n}\n\n/**\n * My own base class for certain React widgets\n */\nclass BaseWidget\u003cS extends BaseState> extends ReactComponent\u003cS> {\n\n    constructor() { \n        super();\n        this._state = {};\n    }\n\n    protected componentWillMount(): void {\n        this.setState({ a: \"boo\" });\n    }\n} \n\n```\n\n```\n$ tsc v1.ts\nv1.ts(39,9): error TS2322: Type '{}' is not assignable to type 'S'.\nv1.ts(43,23): error TS2345: Argument of type '{ a: string; }' is not assignable to parameter of type 'S'.\n```\n\nThe compiler cannot know that the setState() method will accept any super-type of S, i.e. an object with any subset of the members of S.\n## Proposal\n\nAdd a keyword to type setState() properly.  To avoid confusion, I chose **partof** instead of e.g. 'supertype of' (see also initial confusion in #6218). For me, 'partof' conveys that I can give the method any object with a subset of the members of S.  \n\n``` javascript\n/**\n * This class is a given by the React framework\n */\nclass ReactComponent\u003cS extends {}> {\n    protected _state: S;\n\n    /**\n     * This method accepts any supertype of S\n     */\n    protected setState(newState: partof S): void {\n    }\n}\n```\n\n**Properties of partof**\n- Only works for object types (hence the 'extends {}' above) because I wouldn't know how to pass part of e.g. a string\n- Allows any supertype of the given type\n- Incorporates knowledge of the generic parameter. Given the class declaration `class ReactComponent\u003cS extends { foo: number; }>`, one is able to call `setState({ foo: 3})` and `setState({})`  but not `setState({ bar: 3 })` inside the class definition.\n\nComments more than welcome, I'm not a compiler expert. This is just to get the discussion going. If you think there already exists a way of typing this, please check with the original issue for a couple of failed examples.\n","author":{"url":"https://github.com/rogierschouten","@type":"Person","name":"rogierschouten"},"datePublished":"2016-01-25T19:36:53Z","url":"https://github.com/microsoft/TypeScript/issues/6613"}

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:8395668b-e351-2b4c-3ca7-3d69a9d2b0d9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCCE0:E5741:15F342:1D30E5:6AFBDE26
html-safe-nonce013d57f012193a4d33aa8b684983aa745149e0a3788b10a241322e201217a8ed
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0UwOkU1NzQxOjE1RjM0MjoxRDMwRTU6NkFGQkRFMjYiLCJ2aXNpdG9yX2lkIjoiNjgxNDQwOTgyODE4NjQ0NzM5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac0b180b737889152e751cc1a3472b4773ebff30a3dfae599f031c36366d178d4d
hovercard-subject-tagissue:128618856
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/6613/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2ceca45154a1805ee9a22d3dfc8a706e0285c58132252eeff3317be5a026a0e3/microsoft/TypeScript/issues/6613
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2ceca45154a1805ee9a22d3dfc8a706e0285c58132252eeff3317be5a026a0e3/microsoft/TypeScript/issues/6613
og:image:altThis is a proposal for solving the second use case mentioned in Issue #6218 Problem /** * This class is a given by the React framework */ class ReactComponent { protected _state: S; /** * This m...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerogierschouten
hostnamegithub.com
expected-hostnamegithub.com
None744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec
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
releasedf859c48a4c8b4c0009c19bb4e82101aacb4b998
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/6613#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F6613
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%2F6613
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/6613
Reloadhttps://github.com/microsoft/TypeScript/issues/6613
Reloadhttps://github.com/microsoft/TypeScript/issues/6613
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/6613
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/6613
More accurate typing of Object.assign and React component setState()https://github.com/microsoft/TypeScript/issues/6613#top
https://github.com/sandersn
https://github.com/RyanCavanaugh
CommittedThe team has roadmapped this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Committed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/rogierschouten
Rogier Schouten (rogierschouten)https://github.com/rogierschouten
on Jan 25, 2016https://github.com/microsoft/TypeScript/issues/6613#issue-128618856
#6218https://github.com/microsoft/TypeScript/issues/6218
#6218https://github.com/microsoft/TypeScript/issues/6218
Nexthttps://github.com/microsoft/TypeScript/issues/6613?timeline_page=1
https://github.com/rogierschouten
Rogier Schouten (rogierschouten)https://github.com/rogierschouten
on Jan 25, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-174633656
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jan 25, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-174677175
https://github.com/rogierschouten
Rogier Schouten (rogierschouten)https://github.com/rogierschouten
on Jan 25, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-174692821
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 27, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-175314703
https://github.com/rogierschouten
Rogier Schouten (rogierschouten)https://github.com/rogierschouten
on Jan 27, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-175475810
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jan 27, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-175713251
https://github.com/kitsonk
Kitson Kelly (kitsonk)https://github.com/kitsonk
on Jan 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-176191722
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-176286635
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 28, 2016https://github.com/microsoft/TypeScript/issues/6613#event-530010814
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 Jan 28, 2016https://github.com/microsoft/TypeScript/issues/6613#event-530042425
https://github.com/Strate
Artur Eshenbrener (Strate)https://github.com/Strate
on Jan 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-176380865
https://github.com/rogierschouten
Rogier Schouten (rogierschouten)https://github.com/rogierschouten
on Jan 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-176383272
Artur Eshenbrener (@Strate)https://github.com/Strate
#6218https://github.com/microsoft/TypeScript/issues/6218
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Feb 24, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-188065491
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Feb 24, 2016https://github.com/microsoft/TypeScript/issues/6613#event-562944202
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Sep 26, 2016https://github.com/microsoft/TypeScript/issues/6613#event-802838206
https://github.com/sfrooster
Michael Haan (sfrooster)https://github.com/sfrooster
on Oct 11, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-252800277
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Nathan Shively-Sanders (sandersn)https://github.com/sandersn
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 11, 2016https://github.com/microsoft/TypeScript/issues/6613#event-820226684
https://github.com/mDibyo
Dibyo Majumdar (mDibyo)https://github.com/mDibyo
on Nov 17, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-261135216
#12114https://github.com/microsoft/TypeScript/pull/12114
https://github.com/sfrooster
Michael Haan (sfrooster)https://github.com/sfrooster
on Nov 17, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-261150224
#12114https://github.com/microsoft/TypeScript/pull/12114
#12114https://github.com/microsoft/TypeScript/pull/12114
#6613 (comment)https://github.com/microsoft/TypeScript/issues/6613#issuecomment-261135216
https://github.com/notifications/unsubscribe-auth/AC-vl_bEXaisDZ_JaeaRwVSdpr1lC7CPks5q-7kcgaJpZM4HL6Cdhttps://github.com/notifications/unsubscribe-auth/AC-vl_bEXaisDZ_JaeaRwVSdpr1lC7CPks5q-7kcgaJpZM4HL6Cd
https://github.com/dgoldstein0
David Goldstein (dgoldstein0)https://github.com/dgoldstein0
on Dec 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-269437477
#12793https://github.com/microsoft/TypeScript/issues/12793
https://github.com/AlexGalays
Alexandre Galays (AlexGalays)https://github.com/AlexGalays
on Dec 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-269444324
#12793https://github.com/microsoft/TypeScript/issues/12793
https://github.com/Igorbek
Igor Oleinikov (Igorbek)https://github.com/Igorbek
on Dec 28, 2016https://github.com/microsoft/TypeScript/issues/6613#issuecomment-269547129
#10727https://github.com/microsoft/TypeScript/issues/10727
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jun 14, 2017https://github.com/microsoft/TypeScript/issues/6613#issuecomment-308500317
#16524https://github.com/microsoft/TypeScript/issues/16524
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
CommittedThe team has roadmapped this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Committed%22
In DiscussionNot yet reached consensushttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22In%20Discussion%22
on Aug 15, 2017https://github.com/microsoft/TypeScript/issues/6613#event-1206935922
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 15, 2017https://github.com/microsoft/TypeScript/issues/6613#issuecomment-322546032
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 15, 2017https://github.com/microsoft/TypeScript/issues/6613#event-1206936696
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/6613#event-1689634479
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/6613
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/6613
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Nathan Shively-Sanders (sandersn)https://github.com/sandersn
CommittedThe team has roadmapped this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Committed%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.