Title: Using lookahead to detect generic JSX elements? · Issue #6395 · microsoft/TypeScript · GitHub
Open Graph Title: Using lookahead to detect generic JSX elements? · Issue #6395 · microsoft/TypeScript
X Title: Using lookahead to detect generic JSX elements? · Issue #6395 · microsoft/TypeScript
Description: Initially from a couple different comments, but elaborated here. Currently, in order to use a generic JSX element, you must alias both the type and interface to a non-generic specialization. class Select Open Graph Description: Initially from a couple different comments, but elaborated here. Currently, in order to use a generic JSX element, you must alias both the type and interface to a non-generic specialization. class ...
X Description: Initially from a couple different comments, but elaborated here. Currently, in order to use a generic JSX element, you must alias both the type and interface to a non-generic specialization. class ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6395
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using lookahead to detect generic JSX elements?","articleBody":"_Initially from a [couple](https://github.com/Microsoft/TypeScript/issues/3960#issuecomment-165375803) [different](https://github.com/Microsoft/TypeScript/issues/3960#issuecomment-132192858) comments, but elaborated here._\n\nCurrently, in order to use a generic JSX element, you must alias both the type and interface to a non-generic specialization.\n\n``` ts\nclass Select\u003cT> extends React.Component\u003cSelectProps\u003cT>, any> {}\n\n// Alias\ntype StringSelect = new () => Select\u003cstring>\nconst StringSelect = \u003cStringSelect> Select\n\nconst Form = () => \u003cStringSelect items={['a','b']} />\n```\n\nIt would be a _lot_ more convenient and consistent to use something like this:\n\n``` ts\nconst Form = () => \u003cSelect\u003cstring> items={['a', 'b']} />\n```\n\nIn order to differentiate the latter, you can use a single token of lookahead in the parser to know if it's a generic JSX element:\n- If the next token is a `\u003c`, like in `\u003c Select \u003c`, then consume the rest of the type as a generic type. After consuming that:\n - If the next token is a `>`, then finish the type as a generic type cast.\n - If the next token is an identifier or a `{` (for spread attributes, when they get implemented), then parse the rest as a JSX element.\n - Otherwise, parse the rest as a type cast.\n- If the next token is a `>`, like in `\u003c Select >`, then finish the type as a simple type cast.\n- If the next token is an identifier or a `{`, then parse the rest as a JSX element.\n- Otherwise, consume the rest as a type cast.\n\nI don't know of any reason that wouldn't be feasible to do, considering async arrow functions, which are [already implemented](https://github.com/Microsoft/TypeScript/pull/5231), require potentially a whole call expression of parsing to differentiate between `let f = async (x, y)`, which is a call expression, and `let f = async (x, y) => x`, which is an async arrow function. (I feel sorry for whoever ends up implementing that in V8, which doesn't support any backtracking or much lookahead for memory reasons.)\n\n/cc @RyanCavanaugh \n","author":{"url":"https://github.com/dead-claudia","@type":"Person","name":"dead-claudia"},"datePublished":"2016-01-08T09:23:55Z","url":"https://github.com/microsoft/TypeScript/issues/6395"}
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:3680fd5c-dd1e-48dc-99f3-1263b027e067 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id A790:2BE220:D20A3F:1198DB1:6B010075 html-safe-nonce 556bf5b0e81c99276d94b5ae4b588b31b02d63330b73e34f3d7999c5332249f0 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzkwOjJCRTIyMDpEMjBBM0Y6MTE5OERCMTo2QjAxMDA3NSIsInZpc2l0b3JfaWQiOiI2NzcwMjMwMTQxMDE3NzE4OTAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= visitor-hmac f7deeaed27a5e0a755165583b5b315b2861289550a16550ab8236a22419206b6 hovercard-subject-tag issue:125573803 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/6395/issue_layout twitter:image https://opengraph.githubassets.com/f96ed72ad8f577875d75f3689d236bb737374f94efdaf9abd28010440e72e892/microsoft/TypeScript/issues/6395 twitter:card summary_large_image og:image https://opengraph.githubassets.com/f96ed72ad8f577875d75f3689d236bb737374f94efdaf9abd28010440e72e892/microsoft/TypeScript/issues/6395 og:image:alt Initially from a couple different comments, but elaborated here. Currently, in order to use a generic JSX element, you must alias both the type and interface to a non-generic specialization. class ... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username dead-claudia 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
URLs of crawlers that visited me.