Title: Union types and overloads acts a bit weirdly · Issue #33101 · microsoft/TypeScript · GitHub
Open Graph Title: Union types and overloads acts a bit weirdly · Issue #33101 · microsoft/TypeScript
X Title: Union types and overloads acts a bit weirdly · Issue #33101 · microsoft/TypeScript
Description: Acknowledgement I have asked the question on Gitter and most of the users believe it's a bug and I have search for existing issues and didn't found any. Issue Let's start with the code. Playground link declare class Foo { public red(): t...
Open Graph Description: Acknowledgement I have asked the question on Gitter and most of the users believe it's a bug and I have search for existing issues and didn't found any. Issue Let's start with the code. Playground ...
X Description: Acknowledgement I have asked the question on Gitter and most of the users believe it's a bug and I have search for existing issues and didn't found any. Issue Let's start with the code....
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33101
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Union types and overloads acts a bit weirdly","articleBody":"## Acknowledgement\r\nI have asked the question on Gitter and most of the users believe it's a bug and I have search for existing issues and didn't found any.\r\n\r\n## Issue\r\nLet's start with the code. [Playground link](https://www.typescriptlang.org/play/index.html#code/CYUwxgNghgTiAEkoGdnwGIHtPwN4CgBIABwFcAjCASzHjmAAoBKALngBcALK5IsymnRCN2IAB7s2ydjCoA7AOat402YvwBffPlBI4iaKngAhWHj4VqteszZceFgdeENREqTPlKPahZu1gmHLS8ABm2GxYOAA+JmYAvPByIADuGNjM+IHB7PBQ8InhmAB0NgDkbuxlTEA)\r\n\r\n```ts\r\ndeclare class Foo {\r\n\tpublic red(): this\r\n\tpublic red(text: string): string\r\n}\r\n\r\ndeclare class Bar {\r\n\tpublic red(): this\r\n\tpublic red(text: string): string\r\n}\r\n\r\nconst foo: Foo | Bar = new Foo()\r\nconst a = foo.red('text')\r\n```\r\n\r\nIn the above code, I expect the variable `a` to be a string. However, it is `string | Bar`.\r\n\r\nNow, things get even weird when I replace `string` with `object` in the return types of `red` method.\r\n\r\n```ts\r\ndeclare class Foo {\r\n\tpublic red(): this\r\n\tpublic red(text: string): object\r\n}\r\n\r\ndeclare class Bar {\r\n\tpublic red(): this\r\n\tpublic red(text: string): object\r\n}\r\n\r\nconst foo: Foo | Bar = new Foo()\r\nconst a = foo.red('text')\r\n```\r\n\r\nNow suddenly, `a` is an `object` (which is correct)","author":{"url":"https://github.com/thetutlage","@type":"Person","name":"thetutlage"},"datePublished":"2019-08-27T14:36:01Z","url":"https://github.com/microsoft/TypeScript/issues/33101"}
| 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:9aa539a2-1874-b379-3ad2-c2aed4a4a3f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 809E:3670FE:6C5084:92A8C0:6B04CC4B |
| html-safe-nonce | 9a86474fd6e91aa3d15bf35d4d0ca20bc889dca990c1a38faf1527f199b7bf72 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDlFOjM2NzBGRTo2QzUwODQ6OTJBOEMwOjZCMDRDQzRCIiwidmlzaXRvcl9pZCI6IjI1ODc0NDQxMDk0MzQ0NzM1NDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e7eee0117c07197760eae53b0aa9fdbd527b212f8f1536da0b2166d1f937ffa0 |
| hovercard-subject-tag | issue:485850286 |
| 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/33101/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af2b9f40f30b4b6ec498abba5f15fd0b01c339321328384e7859b50bbbf9825d/microsoft/TypeScript/issues/33101 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af2b9f40f30b4b6ec498abba5f15fd0b01c339321328384e7859b50bbbf9825d/microsoft/TypeScript/issues/33101 |
| og:image:alt | Acknowledgement I have asked the question on Gitter and most of the users believe it's a bug and I have search for existing issues and didn't found any. Issue Let's start with the code. Playground ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thetutlage |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27ed421e5c2dac040a37529b5b9191edcc4a3de70521471e81fb4b4d9dc2aa7d |
| 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 | 63dc19014c621c67306d7899c04c78dcd0d95803 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width