Title: Allow JSX element tags to be symbols · Issue #38367 · microsoft/TypeScript · GitHub
Open Graph Title: Allow JSX element tags to be symbols · Issue #38367 · microsoft/TypeScript
X Title: Allow JSX element tags to be symbols · Issue #38367 · microsoft/TypeScript
Description: Search Terms es6 symbols JSX createElement element tag type intrinsic host Suggestion Allow JSX element tags to be ES6 symbols instead of just strings, functions or classes. Use Cases JSX-based libraries like React have adopted the conve...
Open Graph Description: Search Terms es6 symbols JSX createElement element tag type intrinsic host Suggestion Allow JSX element tags to be ES6 symbols instead of just strings, functions or classes. Use Cases JSX-based lib...
X Description: Search Terms es6 symbols JSX createElement element tag type intrinsic host Suggestion Allow JSX element tags to be ES6 symbols instead of just strings, functions or classes. Use Cases JSX-based lib...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/38367
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow JSX element tags to be symbols","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ, especially the \"Common Feature Requests\" section: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\n-->\r\n\r\n## Search Terms\r\n\r\n\u003c!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->\r\n\r\nes6 symbols JSX createElement element tag type intrinsic host\r\n\r\n## Suggestion\r\n\r\nAllow JSX element tags to be ES6 symbols instead of just strings, functions or classes.\r\n\r\n## Use Cases\r\n\r\n\u003c!--\r\nWhat do you want to use this for?\r\nWhat shortcomings exist with current approaches?\r\n-->\r\n\r\nJSX-based libraries like React have adopted the convention of using special upper-cased symbols as the tag of the JSX expression (`\u003cFragment />`, `\u003cSuspense />`) as a way to provide intrinsic elements which aren’t callable and whose behavior are defined by the library rather than the tag.\r\n\r\nCurrently, TypeScript only allows JSX tags to be strings, functions or classes as defined by the JSX interface, and will throw errors like the following if Symbols are used:\r\n\r\n```\r\nerror TS2604: JSX element type 'Fragment' does not have any construct or call signatures.\r\n```\r\n\r\nLibraries are therefore forced to lie about the actual typings of Symbol tags as something other than a `unique symbol`. For instance, React defines Symbol tags as `ExoticComponent` and pretends that the symbols are callable (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L358-L364). The framework I work on (Crank.js) just defines symbols meant to be used as tags as `any` but this then has further repercussions when I attempt to, for instance, use these symbol types in interfaces.\r\n\r\nSymbols are useful because they:\r\n1. Allow intrinsic elements to be upper-cased. This allows people to provide renderer-provided element APIs which mirror XML languages which are case-sensitive.\r\n2. Not globally scoped, so there is no possibility of namespace clashes, and can be imported/exported.\r\n3. Can still work with the global `IntrinsicElements` interfaces to be strongly typed.\r\n\r\n## Examples\r\n\r\n```tsx\r\nconst Fragment = Symbol.for(\"crank.Fragment\");\r\ntype Fragment = typeof Fragment;\r\n\r\nconst Portal = Symbol.for(\"crank.Portal\");\r\ntype Portal = typeof Portal;\r\n\r\n// should not error\r\nconst el = (\r\n \u003cFragment>{children}\u003c/Fragment>\r\n);\r\n\r\ndeclare namespace JSX {\r\n interface IntrinsicElements {\r\n foo: any;\r\n [Portal]: {root: any};\r\n }\r\n}\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n","author":{"url":"https://github.com/brainkim","@type":"Person","name":"brainkim"},"datePublished":"2020-05-06T19:26:50Z","url":"https://github.com/microsoft/TypeScript/issues/38367"}
| 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:e720008a-71e1-b49f-2ccb-4c32dcfcfdc9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFE2:D0E46:F0C713:13E8CA1:6B01049C |
| html-safe-nonce | 9653a5771f925cafc431652c96b6e3d0f00f1672d2feeefaba102e50258e61a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkUyOkQwRTQ2OkYwQzcxMzoxM0U4Q0ExOjZCMDEwNDlDIiwidmlzaXRvcl9pZCI6IjYwMzc3NTU5OTg3NjcyMTk4NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dd233f9731a463c826ce34487ea627d2d685cd1055e959d4bfd8009ebbeece1f |
| hovercard-subject-tag | issue:613557084 |
| 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/38367/issue_layout |
| twitter:image | https://opengraph.githubassets.com/83507c3e5befe1dafae45ebb3e880d3205e1e171fdc837abaee4ef0f946fcbf7/microsoft/TypeScript/issues/38367 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/83507c3e5befe1dafae45ebb3e880d3205e1e171fdc837abaee4ef0f946fcbf7/microsoft/TypeScript/issues/38367 |
| og:image:alt | Search Terms es6 symbols JSX createElement element tag type intrinsic host Suggestion Allow JSX element tags to be ES6 symbols instead of just strings, functions or classes. Use Cases JSX-based lib... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brainkim |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width