Title: TS 3.2 breaks type-unioned component support under certain circumstances · Issue #28795 · microsoft/TypeScript · GitHub
Open Graph Title: TS 3.2 breaks type-unioned component support under certain circumstances · Issue #28795 · microsoft/TypeScript
X Title: TS 3.2 breaks type-unioned component support under certain circumstances · Issue #28795 · microsoft/TypeScript
Description: TypeScript Version: 3.3.0-dev.20181129 Code ex.tsx: import * as React from 'react'; import {BrowserRouter, HashRouter, Redirect, Route, RouteProps, Switch} from 'react-router-dom'; type State = {SelectedRouter?: typeof BrowserRouter | ty...
Open Graph Description: TypeScript Version: 3.3.0-dev.20181129 Code ex.tsx: import * as React from 'react'; import {BrowserRouter, HashRouter, Redirect, Route, RouteProps, Switch} from 'react-router-dom'; type State = {Se...
X Description: TypeScript Version: 3.3.0-dev.20181129 Code ex.tsx: import * as React from 'react'; import {BrowserRouter, HashRouter, Redirect, Route, RouteProps, Switch} from 'react-router-dom'; ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28795
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS 3.2 breaks type-unioned component support under certain circumstances","articleBody":"**TypeScript Version:** 3.3.0-dev.20181129\r\n\r\n**Code**\r\n\r\nex.tsx:\r\n```\r\nimport * as React from 'react';\r\nimport {BrowserRouter, HashRouter, Redirect, Route, RouteProps, Switch} from 'react-router-dom';\r\n\r\ntype State = {SelectedRouter?: typeof BrowserRouter | typeof HashRouter};\r\nexport class Example extends React.Component\u003c{}, State> {\r\n state: State = {};\r\n render() {\r\n const {SelectedRouter} = this.state;\r\n if (!SelectedRouter) return null;\r\n return \u003c>\u003cSelectedRouter>asdf\u003c/SelectedRouter>\u003c/>;\r\n }\r\n}\r\n```\r\n\r\npackage.json:\r\n```\r\n{\r\n \"name\": \"temp\",\r\n \"version\": \"1.0.0\",\r\n \"description\": \"\",\r\n \"author\": \"\",\r\n \"license\": \"ISC\",\r\n \"dependencies\": {},\r\n \"devDependencies\": {\r\n \"@types/prop-types\": \"^15.5.6\",\r\n \"@types/react\": \"^16.7.11\",\r\n \"@types/react-dom\": \"^16.0.11\",\r\n \"@types/react-router\": \"^4.0.32\",\r\n \"@types/react-router-dom\": \"^4.3.1\",\r\n \"csstype\": \"^2.5.7\",\r\n \"typescript\": \"^3.3.0-dev.20181129\"\r\n }\r\n}\r\n```\r\n\r\ntsconfig.json:\r\n```\r\n{\r\n \"compilerOptions\": {\r\n \"lib\": [ \"dom\", \"es2015\" ],\r\n \"module\": \"es2015\",\r\n \"moduleResolution\": \"node\",\r\n \"target\": \"es6\",\r\n \"jsx\": \"react\",\r\n },\r\n \"include\": [ \"*.tsx\" ]\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nSuccessful compilation.\r\n\r\n**Actual behavior:**\r\n\r\n```\r\nex.tsx:10:19 - error TS2604: JSX element type 'SelectedRouter' does not have any construct or call signatures.\r\n\r\n10 return \u003c>\u003cSelectedRouter>asdf\u003c/SelectedRouter>\u003c/>;\r\n ~~~~~~~~~~~~~~\r\n\r\n\r\nFound 1 error.\r\n```\r\n\r\n**Notes:**\r\nThis works with TypeScript 3.1.x, but breaks with 3.2.0+. I am not clear on why certain types work and certain types do not, but I imported the React Router types because they definitely break. I tried creating a test `ComponentA` and `ComponentB` with a render function that returns null, but using a union of `typeof ComponentA | typeof ComponentB` compiles successfully for some reason.\r\n","author":{"url":"https://github.com/bytenik","@type":"Person","name":"bytenik"},"datePublished":"2018-12-01T21:20:46Z","url":"https://github.com/microsoft/TypeScript/issues/28795"}
| 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:eb034440-4724-f09e-d925-090a1ba5b61b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0A0:10D9F8:D8DE0A:11F3D9F:6B00F953 |
| html-safe-nonce | c9aa10691c12dd43f3a62ac4eb5dda8e7269d08d8097b770f1acbb9ad874ac78 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEEwOjEwRDlGODpEOERFMEE6MTFGM0Q5Rjo2QjAwRjk1MyIsInZpc2l0b3JfaWQiOiI2MTMwNzIzNDM4MTk5NDIyMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 89bdad5e51dbc707ffe1c73e552cb3be814de184141feb7637919a426d717a9b |
| hovercard-subject-tag | issue:386498871 |
| 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/28795/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed0866c549d96fe97d7781afe7621dd67aba49068259e0ed58f4c87b0d02c6f7/microsoft/TypeScript/issues/28795 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed0866c549d96fe97d7781afe7621dd67aba49068259e0ed58f4c87b0d02c6f7/microsoft/TypeScript/issues/28795 |
| og:image:alt | TypeScript Version: 3.3.0-dev.20181129 Code ex.tsx: import * as React from 'react'; import {BrowserRouter, HashRouter, Redirect, Route, RouteProps, Switch} from 'react-router-dom'; type State = {Se... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bytenik |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width