Title: 5.0: Narrowing from type-guards ignored when constructing JSX call (2604) · Issue #53178 · microsoft/TypeScript · GitHub
Open Graph Title: 5.0: Narrowing from type-guards ignored when constructing JSX call (2604) · Issue #53178 · microsoft/TypeScript
X Title: 5.0: Narrowing from type-guards ignored when constructing JSX call (2604) · Issue #53178 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms does not have any construct or call signatures.(2604) 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.1-rc (I'm pretty sure it used to work in 5.0.0-beta but can't verify with play...
Open Graph Description: Bug Report 🔎 Search Terms does not have any construct or call signatures.(2604) 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.1-rc (I'm pretty sure it used to work ...
X Description: Bug Report 🔎 Search Terms does not have any construct or call signatures.(2604) 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.1-rc (I'm pretty sure it used ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/53178
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"5.0: Narrowing from type-guards ignored when constructing JSX call (2604)","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\ndoes not have any construct or call signatures.(2604)\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\r\n- This changed between versions 4.9.5 and 5.0.1-rc (I'm pretty sure it used to work in 5.0.0-beta but can't verify with playground)\r\n\r\n### ⏯ Playground Link\r\n\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.1.0-dev.20230309#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQFA0D09cAYgDbIwAywqMACsTCoA2mW68AEjgAmWKAGESkAHZZlMMgF0as3O0pxcEZbzgBZZAE8ARlnEwpyWQqXG1MAFyYqMAHSLwN3UAFUswLAAeZGVLAD44AB9vPD9sFIBRViwQd0S4ZQBXVlY8guVZAmBVaR0sPWQDIxN4e0dnAJV3LzT8f1dVELDI6Li8ntSfTOz3WvrG41MAOQbiAHcsaVaZOQ6gz2Te3YGYUPComNjZ-SxDBfgpnPUAeSgJCF4jroOJjKzH+CSvCgVQA5nRGHAAFIAZQAGnAsH9cjAhuQLDY7DwHNsXIFjmQ4NIIFh0MoIPAABbIABuNxGt2aUAK+Dg0EMyGKcFQwBByg4BUoqF8AAoAEwANgADAAWACUNCapkR03UAEE4ABeb6+HgANQ5wGkD3cwvRti2Th2-XcsrgAH5zFZzVi2la8bkvGbMZIcZ91HAAGQBuARL0W9rW-30S4QmHw5X-OAo8LkcNuzrqAlEkn5clwKm0lAxBlA5nwNm4Dklbm8-mCkUSmXyxXwBPuABCmu1eoNRqR6mFadxGZgtodQ798C8EQnkfg0YYTDjCP78GTNzELt9c6zxNJeYLdOLLaZLIrVa5PL5MAFJIbUrlCruK5VMHkXYAhOMdah9axDcaA6zu66hjiGwEjnA0ZwF4EF7E+zQvv8AAiXYRMsUBrBscHHFBMZLnCSHIqiZCATALxvB8O6EnuuaUjSR6WCWMCnuWUDspyNbXreQpig+zbPm26jpF2349v+favsKZEUe8b5zmBMmvHJk4wSGSmUfJIHzrEQA)\r\n\r\n### 💻 Code\r\n\r\nWe saw 8 errors in our codebase pop up. This might be a fairly common issue in React Native codebases or any codebase having types like `React.ComponentType\u003cany> | React.ReactElement`.\r\n```ts\r\nimport * as React from 'react'\r\n\r\n// `@types/react-native` FlatListProps['ListHeaderComponent']\r\ndeclare const ListHeaderComponent: React.ComponentType\u003cany> | React.ReactElement\r\n\r\n// JSX element type 'ListHeaderComponent' does not have any construct or call signatures.(2604)\r\nconst elementB = React.isValidElement(ListHeaderComponent) ? ListHeaderComponent : \u003cListHeaderComponent />\r\n```\r\n\r\nNote that this works either with either\r\n```diff\r\n-declare const ListHeaderComponent: React.ComponentType\u003cany> | React.ReactElement\r\n+declare const ListHeaderComponent: React.ComponentType\u003cany> | React.ReactElement\u003cunknown>\r\n```\r\nwhich requires a change in `@types/react-native`\r\n\r\nor \r\n\r\n```diff\r\n-declare function isValidElement(maybeElement: unknown): maybeElement is React.ReactElement\u003cunknown>\r\n+declare function isValidElement(maybeElement: unknown): maybeElement is React.ReactElement\u003cany>\r\n```\r\nwhich requires a change in `@types/react`.\r\n\r\nThe change in `@types/react-native` makes more sense but means other type libraries need to update as well.\r\n\r\n3rd option is making `React.ReactElement` default to `React.ReactElement\u003cunkown>` instead of `React.ReactElement\u003cany>` but that might be even more disruptive.\r\n\r\nI'll fiddle with each alternative but I would appreciate if you could check if this new behavior in TypeScript is so valueable to warrant this breakage in the ecosystem.\r\n\r\n### 🙁 Actual behavior\r\n\r\nJSX element type 'ListHeaderComponent' does not have any construct or call signatures.(2604)\r\n\r\n### 🙂 Expected behavior\r\n\r\nNo type error since `isValidElement` narrows to `React.ReactElement` i.e. the else branch should just be `React.ComponentType\u003cany>`\r\n","author":{"url":"https://github.com/eps1lon","@type":"Person","name":"eps1lon"},"datePublished":"2023-03-09T12:50:55Z","url":"https://github.com/microsoft/TypeScript/issues/53178"}
| 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:c5404e7c-17a2-5534-f426-97616eef0b92 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B930:1D86C4:1DF0FD2:25FE74E:6B0160D7 |
| html-safe-nonce | 8bca267b577ff5bf7d69d9206b878835f093cc3f8b1256bec0bc7679b68c5b6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTMwOjFEODZDNDoxREYwRkQyOjI1RkU3NEU6NkIwMTYwRDciLCJ2aXNpdG9yX2lkIjoiMTkwMTY1MTA5OTE0MDU3OTU0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a38205be652bbee8309ca7c832f906a109b9c3259c4abfc78db16563b657adda |
| hovercard-subject-tag | issue:1617174536 |
| 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/53178/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2872d47e44f053da6237fe39f55a6609eb79a2b3ab2691cf514123416a6ae051/microsoft/TypeScript/issues/53178 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2872d47e44f053da6237fe39f55a6609eb79a2b3ab2691cf514123416a6ae051/microsoft/TypeScript/issues/53178 |
| og:image:alt | Bug Report 🔎 Search Terms does not have any construct or call signatures.(2604) 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.1-rc (I'm pretty sure it used to work ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eps1lon |
| 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