Title: [5.0] Intersected array of intersection types with union field not compatible · Issue #53412 · microsoft/TypeScript · GitHub
Open Graph Title: [5.0] Intersected array of intersection types with union field not compatible · Issue #53412 · microsoft/TypeScript
X Title: [5.0] Intersected array of intersection types with union field not compatible · Issue #53412 · microsoft/TypeScript
Description: Bug Report Basically I'm using & types as if subclassing. BaseValue has items array with fewer properties, ExtendedValue extends that with items with more properties. 🔎 Search Terms intersection, ampersand, override, inheritance. Also lo...
Open Graph Description: Bug Report Basically I'm using & types as if subclassing. BaseValue has items array with fewer properties, ExtendedValue extends that with items with more properties. 🔎 Search Terms intersection, a...
X Description: Bug Report Basically I'm using & types as if subclassing. BaseValue has items array with fewer properties, ExtendedValue extends that with items with more properties. 🔎 Search Terms interse...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/53412
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[5.0] Intersected array of intersection types with union field not compatible","articleBody":"# Bug Report\r\n\r\nBasically I'm using `&` types as if subclassing. `BaseValue` has `items` array with fewer properties, `ExtendedValue` extends that with `items` with more properties.\r\n\r\n### 🔎 Search Terms\r\n\r\nintersection, ampersand, override, inheritance. Also looked at the titles of first 2 pages of open issues.\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.9.5 and 5.0.2\r\n- There is an easy work-around, but I'm not sure if it should be necessary.\r\n\r\n### ⏯ Playground Link\r\n\r\n[TypeScript 5.0.2 (error)](https://www.typescriptlang.org/play?ts=5.0.2#code/C4TwDgpgBAQghgZwgSWBAtlAvFA3gWACgooBLAEwC4oA7AV3QCMIAnAbiIF8jRIoBRAB5oa5COVQZssRCjSYAZHiIkxCAMYtSYYKQD2NagmBaaAcygAfWnQA2trh0JEe4aPCQA1OLbrQcBMRQAPTBUMAAFqzQcCzQepGsUABmpBC25AgqZPII1B5yGADaALpO3IS80EIiYuTevv4yXj5+UEqBJKHhUXFQsfGJLClpGVlBpLnUNRCi4pLopeUuzoTqBsZQACr8AMpbA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 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts repro\r\ntype BaseItem = {\r\n id: number;\r\n}\r\ntype ExtendedItem = BaseItem & {\r\n description: string | null\r\n};\r\n\r\n\r\ntype BaseValue = {\r\n // there are other fields\r\n items: BaseItem[];\r\n}\r\ntype ExtendedValue = BaseValue & {\r\n // there are other fields\r\n items: ExtendedItem[];\r\n}\r\n\r\n\r\nconst TEST_VALUE: ExtendedValue = {\r\n items: [ // ❌ ERROR: This is NOT allowed *iff* mixed types are used in `description`\r\n {id: 1, description: null},\r\n {id: 2, description: 'wigglytubble'},\r\n ]\r\n};\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nSeems to me like they should be compatible. Also these examples are ✅ allowed in TS 5.0.2 if `description` only has uniform types, e.g.:\r\n\r\n```ts\r\n// ✅ Allowed: description has only strings\r\nconst ONLY_STRINGS: ExtendedValue = {\r\n items: [\r\n {id: 1, description: 'bollywoggle'},\r\n {id: 2, description: 'wigglytubble'},\r\n ]\r\n};\r\n// ✅ Allowed: description has only nulls\r\nconst ONLY_NULLS: ExtendedValue = {\r\n items: [\r\n {id: 1, description: null},\r\n {id: 2, description: null},\r\n ]\r\n};\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nSeems like it should be allowed.\r\n\r\n### 🙄 Work-around\r\n\r\nTyping `ExtendedValue` with `Omit\u003c>` seems to fix the issue with no obvious downsides.\r\n\r\n```ts\r\ntype ExtendedValue = Omit\u003cBaseValue, 'items'> & {\r\n // there are other fields\r\n items: ExtendedItem[];\r\n}\r\n```\r\n","author":{"url":"https://github.com/intgr","@type":"Person","name":"intgr"},"datePublished":"2023-03-21T16:12:21Z","url":"https://github.com/microsoft/TypeScript/issues/53412"}
| 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:81607028-ed7a-3530-87b2-11f7dbc2b39e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8466:23CF06:2F7AE49:3C7D967:6B01B530 |
| html-safe-nonce | a00a5762727de0322dff4d1640db21a3b8eda87f75fdad0778d763a24f96bdcc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDY2OjIzQ0YwNjoyRjdBRTQ5OjNDN0Q5Njc6NkIwMUI1MzAiLCJ2aXNpdG9yX2lkIjoiMjQ4MTgyNzQzNjI0MTcyODgxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 980781f730caf0978fed32ba6c5445c810e59944419c364bd7ff9ce8efd7f6ee |
| hovercard-subject-tag | issue:1634262197 |
| 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/53412/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7fa22b5882a32b562df682a6790f53f1637330ed38958ad8191ae9f06f2d075e/microsoft/TypeScript/issues/53412 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7fa22b5882a32b562df682a6790f53f1637330ed38958ad8191ae9f06f2d075e/microsoft/TypeScript/issues/53412 |
| og:image:alt | Bug Report Basically I'm using & types as if subclassing. BaseValue has items array with fewer properties, ExtendedValue extends that with items with more properties. 🔎 Search Terms intersection, a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | intgr |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width