Title: Use of implicit union return type causes "'boolean' is not assignable to type 'false'" · Issue #19212 · microsoft/TypeScript · GitHub
Open Graph Title: Use of implicit union return type causes "'boolean' is not assignable to type 'false'" · Issue #19212 · microsoft/TypeScript
X Title: Use of implicit union return type causes "'boolean' is not assignable to type 'false'" · Issue #19212 · microsoft/TypeScript
Description: TypeScript Version: 2.6.0-dev.20171015 This relates to the render method of React components, specifically the use of false in the union return type: render(): JSX.Element | null | false I've create a stand-alone example that demonstrate...
Open Graph Description: TypeScript Version: 2.6.0-dev.20171015 This relates to the render method of React components, specifically the use of false in the union return type: render(): JSX.Element | null | false I've creat...
X Description: TypeScript Version: 2.6.0-dev.20171015 This relates to the render method of React components, specifically the use of false in the union return type: render(): JSX.Element | null | false I've c...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/19212
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use of implicit union return type causes \"'boolean' is not assignable to type 'false'\"","articleBody":"**TypeScript Version:** 2.6.0-dev.20171015\r\n\r\nThis relates to the render method of React components, specifically the use of `false` in the union return type:\r\n```\r\nrender(): JSX.Element | null | false\r\n```\r\n\r\nI've create a stand-alone example that demonstrates the issue. See the code comments for instructions.\r\n\r\n**Code**\r\n\r\n```ts\r\ndeclare class Base {\r\n render(): Date | false;\r\n}\r\n\r\nclass TestImplicitReturnType extends Base {\r\n\r\n render() /* ': false' is required here as explicit return type to prevent a compile error */ {\r\n return false;\r\n }\r\n\r\n}\r\n\r\nclass TestControlFlow extends Base {\r\n\r\n render() {\r\n if (new Date().getTime() % 2 === 0) {\r\n return new Date(); /* removing this return statement causes the false value below to be rejected */ \r\n }\r\n return false;\r\n }\r\n\r\n} \r\n\r\n```\r\n\r\n**Expected behavior:**\r\nFor TestImplicitReturn I should not be required to manually add `: false` as return type.\r\n\r\nFor TestControlFlow I should not be required to also return a Date to satisfy the type checker.\r\n\r\n**Actual behavior:**\r\n\r\nFor TestImplicitReturn the compiler outputs:\r\n```\r\nClass 'TestImplicitReturnType' incorrectly extends base class 'Base'.\r\n Types of property 'render' are incompatible.\r\n Type '() => boolean' is not assignable to type '() => false | Date'.\r\n Type 'boolean' is not assignable to type 'false | Date'.\r\n```\r\n\r\nFor TestImplicitReturnType the compiler outputs the following when the date return statement is removed:\r\n```\r\nClass 'TestControlFlow' incorrectly extends base class 'Base'.\r\n Types of property 'render' are incompatible.\r\n Type '() => boolean' is not assignable to type '() => false | Date'.\r\n Type 'boolean' is not assignable to type 'false | Date'.\r\n```","author":{"url":"https://github.com/jimkyndemeyer","@type":"Person","name":"jimkyndemeyer"},"datePublished":"2017-10-16T13:32:49Z","url":"https://github.com/microsoft/TypeScript/issues/19212"}
| 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:a29669d9-c4e7-b7ba-851d-3b3102d27f68 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB0E:16EED3:C85D88:FFD458:6B01003F |
| html-safe-nonce | 5053bf49063ca6b11af9da34e60258fa4f68a6af29476b503e2156c23093e2e2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjBFOjE2RUVEMzpDODVEODg6RkZENDU4OjZCMDEwMDNGIiwidmlzaXRvcl9pZCI6IjU0MjUyMjA0Mzc0NjAxODkyNDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 68da123f63a18446fb2e7bbb3aa213bdaad6e6192a388c8ce55d477b02e4ad2b |
| hovercard-subject-tag | issue:265771551 |
| 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/19212/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cdd6a6cdbdc266946fd2d6505b29a1d0d6d574fe1d0885b05355fa512af67c9d/microsoft/TypeScript/issues/19212 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cdd6a6cdbdc266946fd2d6505b29a1d0d6d574fe1d0885b05355fa512af67c9d/microsoft/TypeScript/issues/19212 |
| og:image:alt | TypeScript Version: 2.6.0-dev.20171015 This relates to the render method of React components, specifically the use of false in the union return type: render(): JSX.Element | null | false I've creat... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jimkyndemeyer |
| 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 |
Links:
Viewport: width=device-width