Title: Allow JSX intrinsics to have generic call signatures · Issue #42010 · microsoft/TypeScript · GitHub
Open Graph Title: Allow JSX intrinsics to have generic call signatures · Issue #42010 · microsoft/TypeScript
X Title: Allow JSX intrinsics to have generic call signatures · Issue #42010 · microsoft/TypeScript
Description: Search Terms type checking, jsx intrinsics, generic type, signature Suggestion Allow JSX intrinsics defined in IntrinsicElements to support generic call signatures, as is supported for user-defined SFCs. Use Cases Suppose you want to cre...
Open Graph Description: Search Terms type checking, jsx intrinsics, generic type, signature Suggestion Allow JSX intrinsics defined in IntrinsicElements to support generic call signatures, as is supported for user-defined...
X Description: Search Terms type checking, jsx intrinsics, generic type, signature Suggestion Allow JSX intrinsics defined in IntrinsicElements to support generic call signatures, as is supported for user-defined...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/42010
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow JSX intrinsics to have generic call signatures","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\ntype checking, jsx intrinsics, generic type, signature\r\n\r\n## Suggestion\r\n\r\nAllow JSX intrinsics defined in IntrinsicElements to support generic call signatures, as is supported for user-defined SFCs.\r\n\r\n## Use Cases\r\n\r\nSuppose you want to create a small DSL using JSX. You would need to model the primitive statements of the DSL. Your options are intrinsics and user-level components.\r\n\r\nIntrinsics are clearly the more natural fit for this use case. Some reasons are:\r\n* they are immediately available without separate import statements,\r\n* the use of lower case makes them visually distinct from user-defined components,\r\n\r\nHowever, intrinsics are not as capable as user-level components (pre-defined or user-defined). Currently they cannot be assigned generic type signatures. This makes them less expressive, and so, less useful.\r\n\r\nThe proposed change will bring parity between intrinsics and user-level components. In short, it will be possible to create a pre-defined set of intrinsics that are just as expressive as user-level SFCs.\r\n\r\n## Examples\r\n\r\nConsider the following hypothetical DSL in JSX:\r\n\r\n```jsx\r\n\u003cfor items={books} with={book => book.genre === 'scifi'}>\r\n{book => (\r\n \u003cb>{book.title}\u003c/b>\r\n)}\r\n\u003c/for>\r\n```\r\n\r\nCurrently, the `for` intrinsic cannot be generic over the type of the items, unlike user-defined SFCs which may be generic. To bring this capability to intrinsics, we would need to allow JSX.IntrinsicElements to support generic signatures. Here is what it might look like for this example DSL:\r\n\r\n```typescript\r\ndeclare namespace JSX {\r\n interface IntrinsicElements {\r\n for: \u003cT>(props: {\r\n items: T[],\r\n with?: (item: T) => boolean,\r\n children?: (item: T) => Element | Element[]\r\n }) => Element;\r\n\r\n b: { children: string }\r\n }\r\n}\r\n```\r\n\r\nThe implementation of this change will require a small number of changes to `src/compiler/checker.ts`. A good starting point is the function `resolveJsxOpeningLikeElement`.\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\r\n## Request to work on this feature\r\n\r\nI would like to work on this feature improvement.\r\n","author":{"url":"https://github.com/kevin-in-code","@type":"Person","name":"kevin-in-code"},"datePublished":"2020-12-17T12:06:48Z","url":"https://github.com/microsoft/TypeScript/issues/42010"}
| 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:8ae2c9db-d1f2-5817-31ec-ce70e49f36df |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D71E:29AEE8:2714130:3411B3A:6B01AA6B |
| html-safe-nonce | 36f5acc8f0512b462f6548e20598f9fd08aa36c9b2b7b6e23754b3913b211538 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzFFOjI5QUVFODoyNzE0MTMwOjM0MTFCM0E6NkIwMUFBNkIiLCJ2aXNpdG9yX2lkIjoiMTEzMTM5NjY5MzY4MjY2MTk5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2319549fd885e199a3abdaea6c694c26f10929d96e450e80f8f912e6d05e3ef5 |
| hovercard-subject-tag | issue:769943013 |
| 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/42010/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6393af7fb73ee822354c7a03f6d80e4a5b6775250d9d7dfef1a726b00ac50ea9/microsoft/TypeScript/issues/42010 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6393af7fb73ee822354c7a03f6d80e4a5b6775250d9d7dfef1a726b00ac50ea9/microsoft/TypeScript/issues/42010 |
| og:image:alt | Search Terms type checking, jsx intrinsics, generic type, signature Suggestion Allow JSX intrinsics defined in IntrinsicElements to support generic call signatures, as is supported for user-defined... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kevin-in-code |
| 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