Title: Type JSX elements based on createElement function · Issue #14729 · microsoft/TypeScript · GitHub
Open Graph Title: Type JSX elements based on createElement function · Issue #14729 · microsoft/TypeScript
X Title: Type JSX elements based on createElement function · Issue #14729 · microsoft/TypeScript
Description: TypeScript currently uses a JSX namespace to type the props of JSX elements. This is customisable by modifying JSX.IntrinsicElements, JSX.ElementClass. However, the type of an element is always JSX.Element. Of course more interfaces coul...
Open Graph Description: TypeScript currently uses a JSX namespace to type the props of JSX elements. This is customisable by modifying JSX.IntrinsicElements, JSX.ElementClass. However, the type of an element is always JSX...
X Description: TypeScript currently uses a JSX namespace to type the props of JSX elements. This is customisable by modifying JSX.IntrinsicElements, JSX.ElementClass. However, the type of an element is always JSX...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/14729
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type JSX elements based on createElement function","articleBody":"TypeScript currently uses a JSX namespace to type the props of JSX elements. This is customisable by modifying `JSX.IntrinsicElements`, `JSX.ElementClass`. However, the type of an element is always `JSX.Element`.\r\n\r\nOf course more interfaces could be added to the `JSX` namespace. However, I think that with less effort, the compiler could be made more flexible. I'd propose to check JSX elements based on a (virtual) call to `JSX.createElement`. For instance, the current behaviour can approximately be written like this:\r\n\r\n```typescript\r\nnamespace JSX {\r\n // intrinsic elements\r\n function createElement\u003cK extends keyof JSX.IntrinsicElements>(tag: K, props: JSX.IntrinsicElements[K], children: JSX.Element[]): JSX.Element;\r\n // class and functional components\r\n function createElement\u003cP>(component: (JSX.ElementClass & { new(): { props: P } }) | ((props: P) => JSX.Element), props: P, children: JSX.Element[]): JSX.Element;\r\n}\r\n```\r\n\r\nGiven that function signatures are well customisable with the use of generics for instance, most requests can be implemented this way. For instance, #13890 and #13618 would benefit from this change. Libraries that use JSX, but not on the React-way, will benefit from this too.\r\n\r\n## Proposed semantics\r\nFor a JSX element, a virtual call to `JSX.createElement` is constructed. It is passed three arguments:\r\n\r\n1. Tag name (string) in case of an intrinsic argument (`\u003cdiv />`). Otherwise, the identifier is passed (`Foo` for `\u003cFoo />`).\r\n2. An object containing the props.\r\n3. An array containing the children.\r\n\r\nThis should be roughly the same as the JSX transform used in the emitter phase. One notable difference is the following: in case of no properties or no children, an empty object or an empty array should be passed, instead ignoring the argument. This makes it easier to write `JSX.createElement` for library authors.\r\n\r\n## Backwards compatibility\r\nFor backwards compatibility, one of the following approaches could be taken:\r\n\r\n- Use old logic if `JSX.createElement` does not exist.\r\n- If `JSX.createElement` does not exist, default it to (roughly) the definition above.\r\n\r\n## Error reporting\r\nWhen type checking the generated function call, the checker can give error messages like \"Argument of type .. \" or \"Supplied parameters do not match any signature of call target\". These messages should be replaced when checking JSX elements.","author":{"url":"https://github.com/ivogabe","@type":"Person","name":"ivogabe"},"datePublished":"2017-03-19T13:58:56Z","url":"https://github.com/microsoft/TypeScript/issues/14729"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:74af7b26-14d3-93a2-7864-2c2e2bcc3c67 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB8E:A20F9:AF66F5:EAD061:6B00ED13 |
| html-safe-nonce | d13491daf6df8418529b77c5621b5242b40902efa6364a602349e12046c58633 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjhFOkEyMEY5OkFGNjZGNTpFQUQwNjE6NkIwMEVEMTMiLCJ2aXNpdG9yX2lkIjoiNTg5MzcyMDcwOTk2Nzk2NTQ2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d78aa37d62cce04c9b51b5e8f066d6cc7a94f64fb3c22d2d92b9a36a4a6a7930 |
| hovercard-subject-tag | issue:215265738 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/14729/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d3c3d8be6bc5b018aae1291b3fc52719e63dad2e271875a426e8d66e4e8014e3/microsoft/TypeScript/issues/14729 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d3c3d8be6bc5b018aae1291b3fc52719e63dad2e271875a426e8d66e4e8014e3/microsoft/TypeScript/issues/14729 |
| og:image:alt | TypeScript currently uses a JSX namespace to type the props of JSX elements. This is customisable by modifying JSX.IntrinsicElements, JSX.ElementClass. However, the type of an element is always JSX... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ivogabe |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width