Title: Inference doesn't find common base type for union with null or undefined - TypeScript 4.8 regression · Issue #49938 · microsoft/TypeScript · GitHub
Open Graph Title: Inference doesn't find common base type for union with null or undefined - TypeScript 4.8 regression · Issue #49938 · microsoft/TypeScript
X Title: Inference doesn't find common base type for union with null or undefined - TypeScript 4.8 regression · Issue #49938 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms inference common base type null undefined 🕗 Version & Regression Information This changed between versions 4.7.3 and 4.8-beta ⏯ Playground Link Playground link with relevant code 💻 Code function equal
Open Graph Description: Bug Report 🔎 Search Terms inference common base type null undefined 🕗 Version & Regression Information This changed between versions 4.7.3 and 4.8-beta ⏯ Playground Link Playground link with releva...
X Description: Bug Report 🔎 Search Terms inference common base type null undefined 🕗 Version & Regression Information This changed between versions 4.7.3 and 4.8-beta ⏯ Playground Link Playground link with re...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/49938
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inference doesn't find common base type for union with null or undefined - TypeScript 4.8 regression","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\ninference common base type null undefined \r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.7.3 and 4.8-beta\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.8.0-beta#code/GYVwdgxgLglg9mABAUwI4gIYBsA8AVAPgAoMAuRPAGkQCNy8BKRAb0QF8AoDrZKRAN0QBeRGBBYsAQgDcXDgHp5iAPI0AVsmiIoATwAOyAM6IA7jCgALRBDgBbWwloZDybfqNddBxACFhLRGA4OHJDKAAnGDAAc3YOL1cAEX9WIJDEMMiY6Sdw8jFbGmRwuIUlAFFw8LgSqMQAFgA6AA4KAGVrDDAAcj5gKIATazsHJATEQBlyMobGgHYKU2dEcAHkfrBkIYAfXw40TCwiQSWfamPjFbWozcQdxIYuRUQ4AGsFmGM-QFByPfRsI8QJzOgOM92mr3en1uyzAq3WNx++3+518wJO0Mu8IGDwUACpcRxELiVJZiigAB4YWx6HiGQm4+SPJQABUitnMMH4RkBsMQWHMxWwdOmlWqtSQTVaeA6EC6vUCg2G9kc4ymTya8zwiwusKuG22ohAhWKvwOAKWBSK4TROrh1wNAAZoQBGaEAJhxTwhWo+huNJURf0OKMtxRtiEQTp2rp2HtkXrePuMoZKO0x9sQgbNIaNVvDfqtGN1WIYsiZiAAglUMDpjGZLErRk4XG4DMKnqKaog6pL2p0en1FTZlWN3JNphqFiYlun9dCiCnoZkotEGABtAC6puRIMQC9zZJ2y5i6434dnNx2Kc3nqU3u7xn3-qXERXp8z2+Du6fhaPr5Pm7hteG4PAmkJ7ouf5ZKum5Fnac5ZjuSw-oeGT-jBZ4CN+kFodB75psW9oPEAA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nfunction equal\u003cT>(a: T, b: T) { }\r\n\r\nlet v = null!;\r\n\r\n// Object types with common base types\r\n\r\ntype B = { foo: string }\r\ntype D = { foo: string; bar: number }\r\n\r\n// Error in 4.8 TS can't find common type ❌\r\n// 4.7 T was undefined | B\r\nequal(v as B, v as undefined | D)\r\n\r\n// ok T is B ✅\r\nequal(v as B, v as D)\r\n// ok T is B | undefined ✅\r\nequal(v as B, v as B | undefined)\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nIn 4.8 TypeScript can't find common base type between `B` and `undefined | D`. In 4.7 this used to be `B | undefined`. \r\n\r\nThis also happens for literal types and their respective base types as well as for arrays as shown in the 'Other Examples' in the playground link. I didn't include the code as the bug is the same, it's just different instances we found in our code.\r\n\r\n### 🙂 Expected behavior\r\n\r\nTypescript finds the type `B | undefined` for `T` as it did in 4.7.\r\n","author":{"url":"https://github.com/dragomirtitian","@type":"Person","name":"dragomirtitian"},"datePublished":"2022-07-18T08:55:50Z","url":"https://github.com/microsoft/TypeScript/issues/49938"}
| 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:006fb211-e784-c7d7-c4e5-5398cfc9c7cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9ECA:16AB79:C6ECD5:FDE6C1:6B00FF2A |
| html-safe-nonce | d4703a0ab86476cc4e8274a905fc8135097530ebda14b2e53bb8cd9f72d16ccf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUNBOjE2QUI3OTpDNkVDRDU6RkRFNkMxOjZCMDBGRjJBIiwidmlzaXRvcl9pZCI6Ijg1MTMxNDE0OTc2NjU3NDg3NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1280ec46565e24265c13e887456dfb61dbfe6bb13e0954127eaedad545e864d1 |
| hovercard-subject-tag | issue:1307614581 |
| 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/49938/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b3c3287c577e7416f7e6800ccd85ffd00ba95785ad9b8a2e3569da470e97b617/microsoft/TypeScript/issues/49938 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b3c3287c577e7416f7e6800ccd85ffd00ba95785ad9b8a2e3569da470e97b617/microsoft/TypeScript/issues/49938 |
| og:image:alt | Bug Report 🔎 Search Terms inference common base type null undefined 🕗 Version & Regression Information This changed between versions 4.7.3 and 4.8-beta ⏯ Playground Link Playground link with releva... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dragomirtitian |
| 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