Title: extends converts type of the form A | B to A & B · Issue #36445 · microsoft/TypeScript · GitHub
Open Graph Title: extends converts type of the form A | B to A & B · Issue #36445 · microsoft/TypeScript
X Title: extends converts type of the form A | B to A & B · Issue #36445 · microsoft/TypeScript
Description: TypeScript Version: 3.7.2 Search Terms: extends, type inference Code Key parts to look at in this code are the definition of funcA which specifies the type of the argument to be A | B, but since it is typed as Slowboy
Open Graph Description: TypeScript Version: 3.7.2 Search Terms: extends, type inference Code Key parts to look at in this code are the definition of funcA which specifies the type of the argument to be A | B, but since it...
X Description: TypeScript Version: 3.7.2 Search Terms: extends, type inference Code Key parts to look at in this code are the definition of funcA which specifies the type of the argument to be A | B, but since it...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36445
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"extends converts type of the form A | B to A & B","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:** 3.7.2\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** extends, type inference\r\n\r\n**Code**\r\nKey parts to look at in this code are the definition of `funcA` which specifies the type of the argument to be `A | B`, but since it is typed as `Slowboy\u003cPayload>` it goes through an `extends undefined` check which changes the expected argument type of `funcA` from `A | B` to `A & B`.\r\n\r\n```ts\r\n\r\ntype A = {\r\n isNew: true;\r\n extra: {\r\n name: string,\r\n age: number\r\n }\r\n}\r\n\r\ntype B = {\r\n isNew: false;\r\n}\r\n\r\ntype AorB = A | B\r\n\r\ntype Data\u003cT> = {\r\n name: string;\r\n payload: T \r\n}\r\n\r\ntype SlowBoy\u003cPayload> = Payload extends undefined ?\r\n (payload?: undefined) => Data\u003cundefined> :\r\n (payload: Payload) => Data\u003cPayload>;\r\n\r\n\r\nconst funcA: SlowBoy\u003cAorB> = (payload: AorB) => ({\r\n name: \"A\",\r\n payload\r\n})\r\n\r\nfuncA({ //Shows the expected type of argument to funcA as A & B\r\n isNew: true,\r\n extra: {\r\n name: 'ijxsid',\r\n age: 310\r\n }\r\n})\r\n```\r\n\r\n**Expected behavior:**\r\nI expect the `extends` keyword to check if the `Payload` type extends undefined and if its the second case in which the `Payload` doesn't extend undefined, the `Payload` type should remain as applied in the definition of `funcA`, that is `A | B`.\r\n\r\n\r\n**Actual behavior:**\r\nThe `Payload` type applied in the definition of `funcA` gets modified by the `extends` type check from `A | B` to `A & B`.\r\n\r\nIs this the expected behavior of extends? Cause I don't think the type checks done by `extends undefined` should stay after the check has already determined the type. \r\n\r\n\r\n\r\n**Playground Link:** \u003c!-- A link \r\nto a TypeScript Playground \"Share\" link which demonstrates this behavior --> https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=37&pc=3#code/FAFwngDgpgBAgjAvDA3sGGYEsDOA5KAdwC4YQAnAVygG51MoAPCgQ1LU05gDsWBbKKRwUs3AOYAaelxgsxgnpT4AjKOWkwAvsG2hIsAEJJUG3ARIwAZiwA2OWjuB7o8APbkjyBAB8YBp+AuACIsICwAPAAqAHzGHJi8AkIi4nScECxgNq4sACakkTCOzrAAytmEBq5g4QAKmdl5scj1WTm5MEwgUNy5ODCUvVCWolAdAPwaABQZbXnjpIO5w6O5AJRIsSFh4Usr3GOxxNOzjfkwrWcbiFuhEZft0XROAMau3MJWgy9wpOWulWq4Tg7gMzRgMwa7VIII811iU3iGESCgARHBUVJ0lC8jo1k5LN84IjTPgiKQKNQsQxmOQ2CYZMj+AoAORYABWjBwWFyLOpMjkCgAzABGAAMGm0mjWQA\r\n\r\nHover over the `funcA` call and it shows the expected argument type to be `A & B`\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/ijxsid2","@type":"Person","name":"ijxsid2"},"datePublished":"2020-01-27T02:54:20Z","url":"https://github.com/microsoft/TypeScript/issues/36445"}
| 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:0039c1b7-4e81-81ed-8d4e-2dc934f6445d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D0EA:2C3566:93BF0C:C5BB5B:6B00E1BC |
| html-safe-nonce | 87848098911c2ad496cb56569d184d4fb55f6197e409b86966455fa66165f6c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEVBOjJDMzU2Njo5M0JGMEM6QzVCQjVCOjZCMDBFMUJDIiwidmlzaXRvcl9pZCI6Ijg0MTAyODg4OTc5MjExODAwOTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6910ef2e1c57f904294e3ab62fd3c934be5c492ccaf55711aa1cdb4edad8636b |
| hovercard-subject-tag | issue:555333746 |
| 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/36445/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6a962ab4662530a95632481d0b0795a52c6df6a45c2801aa7a583420e3109ced/microsoft/TypeScript/issues/36445 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6a962ab4662530a95632481d0b0795a52c6df6a45c2801aa7a583420e3109ced/microsoft/TypeScript/issues/36445 |
| og:image:alt | TypeScript Version: 3.7.2 Search Terms: extends, type inference Code Key parts to look at in this code are the definition of funcA which specifies the type of the argument to be A | B, but since it... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ijxsid2 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width