Title: Slow Performance with Type Inference on JSX Element · Issue #43717 · microsoft/TypeScript · GitHub
Open Graph Title: Slow Performance with Type Inference on JSX Element · Issue #43717 · microsoft/TypeScript
X Title: Slow Performance with Type Inference on JSX Element · Issue #43717 · microsoft/TypeScript
Description: Version TypeScript 4.2.4 TypeScript 4.3.0-dev.20210417 Expected Behaviour Any changes made to the Box component have fast validation and auto-completion for associated attributes. Actual Behaviour TypeScript validation and auto-completio...
Open Graph Description: Version TypeScript 4.2.4 TypeScript 4.3.0-dev.20210417 Expected Behaviour Any changes made to the Box component have fast validation and auto-completion for associated attributes. Actual Behaviour ...
X Description: Version TypeScript 4.2.4 TypeScript 4.3.0-dev.20210417 Expected Behaviour Any changes made to the Box component have fast validation and auto-completion for associated attributes. Actual Behaviour ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/43717
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Slow Performance with Type Inference on JSX Element","articleBody":"**Version**\r\nTypeScript 4.2.4\r\nTypeScript 4.3.0-dev.20210417\r\n\r\n**Expected Behaviour**\r\nAny changes made to the `Box` component have fast validation and auto-completion for associated attributes.\r\n\r\n**Actual Behaviour**\r\nTypeScript validation and auto-completion is slow.\r\n\r\n**Description**\r\nI have been investigating the current trend to create a generic React element which will pass through an `element` property and associated attributes and call `React.createElement`. An approach similar to this is used by several prominent projects such as [Material UI](https://github.com/mui-org/material-ui) and [Github Primer](https://github.com/primer/components). I wanted to ensure that TypeScript will infer the correct attributes from the given `element` property. The code I wrote does work, however it does appear to have a significant performance impact.\r\n\r\n**Related**\r\nThis issue may be related to these issues: #34801, #43485, #42010, #14729, #38583.\r\n\r\n**Example**\r\nA small, reproducible example can be found at: https://github.com/scottwillmoore/react-box. You can also experiment with it in [CodeSandbox](https://codesandbox.io/s/react-with-typescript-inferred-properties-8h2jo?file=/src/App.tsx). The CodeSandbox version has some differences.\r\n\r\nThe meat of the TypeScript can be seen below:\r\n\r\n````tsx\r\nimport React from \"react\";\r\n\r\ntype ElementType = keyof JSX.IntrinsicElements;\r\n\r\ntype ElementProperties\u003cT extends ElementType> = JSX.IntrinsicElements[T];\r\n\r\ntype WithElement\u003cT extends ElementType> = {\r\n element: T;\r\n} & ElementProperties\u003cT>;\r\n\r\ntype WithChildren = {\r\n children?: React.ReactNode;\r\n};\r\n\r\ntype BoxProperties\u003cT extends ElementType> = WithElement\u003cT> & WithChildren;\r\n\r\nfunction Box\u003cT extends ElementType>({ element, children, ...properties }: BoxProperties\u003cT>) {\r\n return React.createElement(element, properties, children);\r\n}\r\n\r\nexport default function App() {\r\n return (\r\n \u003cBox element=\"a\" href=\"#\">\r\n Hello, world!\r\n \u003c/Box>\r\n );\r\n}\r\n````","author":{"url":"https://github.com/scottwillmoore","@type":"Person","name":"scottwillmoore"},"datePublished":"2021-04-17T12:26:13Z","url":"https://github.com/microsoft/TypeScript/issues/43717"}
| 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:30a661b8-d595-4f49-1165-82dd9841a73d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9776:14F601:2D2C0D5:3950965:6B019DE9 |
| html-safe-nonce | 1fb6cca17ced100cc5255da0255f09a918197ac0055300dc398f681533121766 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Nzc2OjE0RjYwMToyRDJDMEQ1OjM5NTA5NjU6NkIwMTlERTkiLCJ2aXNpdG9yX2lkIjoiNjU3OTc5MTE4ODAzMzkwNDEwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 45f8c9b0dfd3c2d98a77ba4578bd31215fae75c5bb3ceed4c0d5fc980fe45499 |
| hovercard-subject-tag | issue:860399254 |
| 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/43717/issue_layout |
| twitter:image | https://opengraph.githubassets.com/422189447c28bac90f7dad8bb2ea97511f4b6ff1a52ec9b9e55c013c30cfa677/microsoft/TypeScript/issues/43717 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/422189447c28bac90f7dad8bb2ea97511f4b6ff1a52ec9b9e55c013c30cfa677/microsoft/TypeScript/issues/43717 |
| og:image:alt | Version TypeScript 4.2.4 TypeScript 4.3.0-dev.20210417 Expected Behaviour Any changes made to the Box component have fast validation and auto-completion for associated attributes. Actual Behaviour ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scottwillmoore |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width