René's URL Explorer Experiment


Title: Suggestion: type checking for JSX children · Issue #13618 · microsoft/TypeScript · GitHub

Open Graph Title: Suggestion: type checking for JSX children · Issue #13618 · microsoft/TypeScript

X Title: Suggestion: type checking for JSX children · Issue #13618 · microsoft/TypeScript

Description: Rationale Props are an important part of a React component's interface, but children can be as well. In applications it's not uncommon to want to restrict what kind of children a component will accept. Currently this enforcement has to b...

Open Graph Description: Rationale Props are an important part of a React component's interface, but children can be as well. In applications it's not uncommon to want to restrict what kind of children a component will acc...

X Description: Rationale Props are an important part of a React component's interface, but children can be as well. In applications it's not uncommon to want to restrict what kind of children a component ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: type checking for JSX children","articleBody":"## Rationale\r\nProps are an important part of a React component's interface, but children can be as well.\r\nIn applications it's not uncommon to want to restrict what kind of children a component will\r\naccept. Currently this enforcement has to be done at runtime by throwing errors.\r\n\r\n## The Goal\r\nComponents can specify allowed children as a union type. Each member would correspond to\r\nthe tag, or 'type' field, of the resulting Element. Ideally this could be plucked from\r\nthe type of props.children, which would satisfy both component classes and SFCs.\r\n\r\n## Motivating Examples:\r\nA modal component may want to make assumptions about its children to satisfy layout\r\nconstraints.\r\n```jsx\r\ninterface IModalProps {\r\n    children: ModalHeader | ModalBody | ModalFooter;\r\n}\r\n\r\nfunction Modal({ children }: IModalProps) { ... }\r\nfunction ModalHeader(props) { ... }\r\nfunction ModalBody(props) { ... }\r\nfunction ModalFooter(props) { ... }\r\n\r\n\u003cModal>\r\n    \u003cModalHeader />\r\n    \u003cdiv /> { /* Desired error: type 'div' does not exist in type 'ModalHeader | ModalBody | ModalFooter' */ }\r\n    \u003cModalBody />\r\n    \u003cModalFooter />\r\n\u003c/Modal>\r\n```\r\n\r\nSimilarly...\r\n```jsx\r\ninterface IButtonGroupProps {\r\n    children: 'button';\r\n}\r\n\r\nfunction ButtonGroup({ children }: IButtonGroupProps) { ... }\r\n\r\n\u003cButtonGroup>\r\n    \u003cbutton />\r\n    \u003cbutton />\r\n    \u003ca href='' /> { /* Desired error: type 'a' is not assignable to type 'button' */ }\r\n\u003c/ButtonGroup>\r\n```\r\n\r\nAn interesting emerging pattern is using JSX as a function call to turn imperative APIs into\r\ndeclarative ones. Currently these 'render callbacks' can't be type-checked at all. A more complete\r\nsummary can be found at http://reactpatterns.com/#render-callback. A further example can be found at https://github.com/ReactTraining/react-media#usage.\r\n```jsx\r\ninterface IUser {\r\n    Name: string;\r\n}\r\n\r\ninterface IFetchUserProps {\r\n    children(user: IUser): any;\r\n}\r\n\r\nclass FetchUser extends React.Component\u003cIFetchUserProps, any> {\r\n    render() {\r\n        return this.state\r\n            ? this.props.children(this.state.result)\r\n            : null;\r\n    }\r\n\r\n    componentDidMount() {\r\n        api.fetchUser().then(result => this.setState({ result }));\r\n    }\r\n}\r\n\r\nfunction UserName() {\r\n    return (\r\n        \u003cFetchUser>\r\n            { user => (\r\n                \u003ch1>{ user.NAme }\u003c/h1> // Desired error: property 'NAme' does not exist on type 'IUser'\r\n            ) }\r\n        \u003c/FetchUser>\r\n    );\r\n}\r\n```\r\n\r\nLastly, I don't *think* any of this is necessarily specific to React. Other libraries leveraging the JSX\r\nspecification for component structure should be able to leverage this as well. The crux of this lies at\r\nthe relationship between the type of the 'children' attribute of a given tag and the children actually\r\npassed to it at usage sites.\r\n","author":{"url":"https://github.com/jwbay","@type":"Person","name":"jwbay"},"datePublished":"2017-01-21T18:56:26Z","url":"https://github.com/microsoft/TypeScript/issues/13618"}

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:4103535f-f753-4bf3-7bac-7338ed1a4473
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC8AE:4BB79:B00869:E2204C:6B00F94E
html-safe-nonce8170983d0c38ff5c6a81c578abe0f1b7d43a8e478cb459ed04524ff19659d4e1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEFFOjRCQjc5OkIwMDg2OTpFMjIwNEM6NkIwMEY5NEUiLCJ2aXNpdG9yX2lkIjoiODkxNzI5MTQ5NDk0ODI3MjQ2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac29b724d416f24c6c90097133374a59947e9b7c637bcecf5492c04fdad61a2271
hovercard-subject-tagissue:202333206
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/13618/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9c4508fbd336ca30999e4e53209f687f89fc373ac6898d0229327221f8ad4477/microsoft/TypeScript/issues/13618
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9c4508fbd336ca30999e4e53209f687f89fc373ac6898d0229327221f8ad4477/microsoft/TypeScript/issues/13618
og:image:altRationale Props are an important part of a React component's interface, but children can be as well. In applications it's not uncommon to want to restrict what kind of children a component will acc...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejwbay
hostnamegithub.com
expected-hostnamegithub.com
Nonee208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187
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
release7dafd017fb7809a839c443dba08622af38e63c09
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/13618#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F13618
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%2F13618
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/13618
Reloadhttps://github.com/microsoft/TypeScript/issues/13618
Reloadhttps://github.com/microsoft/TypeScript/issues/13618
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests309 (309)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/13618
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/13618
Suggestion: type checking for JSX childrenhttps://github.com/microsoft/TypeScript/issues/13618#top
Domain: JSX/TSXRelates to the JSX parser and emitterhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20JSX%2FTSX%22
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
TypeScript 2.3.1https://github.com/microsoft/TypeScript/milestone/42
https://github.com/jwbay
jwbayhttps://github.com/jwbay
on Jan 21, 2017https://github.com/microsoft/TypeScript/issues/13618#issue-202333206
http://reactpatterns.com/#render-callbackhttp://reactpatterns.com/#render-callback
https://github.com/ReactTraining/react-media#usagehttps://github.com/ReactTraining/react-media#usage
Nexthttps://github.com/microsoft/TypeScript/issues/13618?timeline_page=1
https://github.com/joelday
Joel Day (joelday)https://github.com/joelday
on Jan 30, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-275994489
jwbayhttps://github.com/jwbay
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
joelday@50870c1https://github.com/joelday/TypeScript/commit/50870c13ccaefb6efb61f2889788488d5e594f14
https://github.com/jwbay
jwbayhttps://github.com/jwbay
on Feb 2, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-276850961
Joel Day (@joelday)https://github.com/joelday
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Feb 2, 2017https://github.com/microsoft/TypeScript/issues/13618#event-947346786
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Yui (yuit)https://github.com/yuit
on Feb 2, 2017https://github.com/microsoft/TypeScript/issues/13618#event-947346871
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
TypeScript 2.3https://github.com/microsoft/TypeScript/milestone/38
on Feb 2, 2017https://github.com/microsoft/TypeScript/issues/13618#event-947347007
https://github.com/joelday
Joel Day (joelday)https://github.com/joelday
on Feb 9, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-278744508
Yui (@yuit)https://github.com/yuit
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
Yui (yuit)https://github.com/yuit
Domain: JSX/TSXRelates to the JSX parser and emitterhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20JSX%2FTSX%22
on Feb 16, 2017https://github.com/microsoft/TypeScript/issues/13618#event-965269150
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Salsahttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Salsa%22
on Mar 23, 2017https://github.com/microsoft/TypeScript/issues/13618#event-1013288097
https://github.com/joelday
Joel Day (joelday)https://github.com/joelday
on Mar 29, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-290165273
Yui (@yuit)https://github.com/yuit
https://github.com/petdun2519
petdun2519https://github.com/petdun2519
on Apr 3, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-291288786
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
TypeScript 2.3https://github.com/microsoft/TypeScript/milestone/38
TypeScript 2.3.1https://github.com/microsoft/TypeScript/milestone/42
on Apr 4, 2017https://github.com/microsoft/TypeScript/issues/13618#event-1029169880
https://github.com/yuit
Yui (yuit)https://github.com/yuit
on Apr 6, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-292289289
Joel Day (@joelday)https://github.com/joelday
petdun2519https://github.com/petdun2519
https://github.com/donaldpipowitch
Donald Pipowitch (donaldpipowitch)https://github.com/donaldpipowitch
on Aug 8, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-320855453
#15589https://github.com/microsoft/TypeScript/issues/15589
Donald Pipowitch (donaldpipowitch)https://github.com/donaldpipowitch
Yui (yuit)https://github.com/yuit
on Aug 8, 2017https://github.com/microsoft/TypeScript/issues/13618#event-1196572304
https://github.com/donaldpipowitch
Donald Pipowitch (donaldpipowitch)https://github.com/donaldpipowitch
on Aug 8, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-320855603
https://github.com/antanas-arvasevicius
Antanas A. (antanas-arvasevicius)https://github.com/antanas-arvasevicius
on Aug 8, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-320856296
…https://github.com/microsoft/TypeScript/issues/13618
https://user-images.githubusercontent.com/1152805/29057701-a71543a2-7c0c-11e7-88db-5edef0b77456.pnghttps://user-images.githubusercontent.com/1152805/29057701-a71543a2-7c0c-11e7-88db-5edef0b77456.png
#13618 (comment)https://github.com/microsoft/TypeScript/issues/13618#issuecomment-320855603
https://github.com/notifications/unsubscribe-auth/AEAcnA_fYkJzzRqyyGGF09p61Rz9tXLLks5sV_SagaJpZM4LqJuYhttps://github.com/notifications/unsubscribe-auth/AEAcnA_fYkJzzRqyyGGF09p61Rz9tXLLks5sV_SagaJpZM4LqJuY
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 8, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-321083772
Donald Pipowitch (@donaldpipowitch)https://github.com/donaldpipowitch
https://github.com/jwbay
jwbayhttps://github.com/jwbay
on Aug 8, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-321105296
https://github.com/donaldpipowitch
Donald Pipowitch (donaldpipowitch)https://github.com/donaldpipowitch
on Aug 9, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-321286440
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup
https://github.com/patsissons
Pat Sissons (patsissons)https://github.com/patsissons
on Aug 31, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-326412898
https://github.com/donaldpipowitch
Donald Pipowitch (donaldpipowitch)https://github.com/donaldpipowitch
on Sep 7, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-327910285
https://github.com/gitsupersmecher
SupSm (gitsupersmecher)https://github.com/gitsupersmecher
on Oct 26, 2017https://github.com/microsoft/TypeScript/issues/13618#issuecomment-339528821
https://github.com/dontsave
dave kraftsow (dontsave)https://github.com/dontsave
on Jan 6, 2018https://github.com/microsoft/TypeScript/issues/13618#issuecomment-355778738
https://github.com/luixo
Alexey Immoreev (luixo)https://github.com/luixo
on Feb 1, 2018https://github.com/microsoft/TypeScript/issues/13618#issuecomment-362402766
https://github.com/jchitel
Jake Chitel (jchitel)https://github.com/jchitel
on Feb 13, 2018https://github.com/microsoft/TypeScript/issues/13618#issuecomment-365160765
this issuehttps://github.com/microsoft/TypeScript/issues/13618#14729
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Feb 13, 2018https://github.com/microsoft/TypeScript/issues/13618#issuecomment-365161347
#21699https://github.com/microsoft/TypeScript/issues/21699
microsofthttps://github.com/microsoft
on Jul 25, 2018https://github.com/microsoft/TypeScript/issues/13618#event-1753409579
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/13618
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/13618
Domain: JSX/TSXRelates to the JSX parser and emitterhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Domain%3A%20JSX%2FTSX%22
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
TypeScript 2.3.1https://github.com/microsoft/TypeScript/milestone/42
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.