Title: Map derived from discriminated union has wrong type when discriminator property has the same value · Issue #37859 · microsoft/TypeScript · GitHub
Open Graph Title: Map derived from discriminated union has wrong type when discriminator property has the same value · Issue #37859 · microsoft/TypeScript
X Title: Map derived from discriminated union has wrong type when discriminator property has the same value · Issue #37859 · microsoft/TypeScript
Description: TypeScript Version: 3.8.3 Search Terms: map from discriminated union same key discriminated union same key Expected behavior: CatMap should have type type CatMap = { cat: TerrestrialCat[] | AlienCat[]; } Actual behavior: CatMap has type ...
Open Graph Description: TypeScript Version: 3.8.3 Search Terms: map from discriminated union same key discriminated union same key Expected behavior: CatMap should have type type CatMap = { cat: TerrestrialCat[] | AlienCa...
X Description: TypeScript Version: 3.8.3 Search Terms: map from discriminated union same key discriminated union same key Expected behavior: CatMap should have type type CatMap = { cat: TerrestrialCat[] | AlienCa...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/37859
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Map derived from discriminated union has wrong type when discriminator property has the same value","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**TypeScript Version:** 3.8.3\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\n\r\n* map from discriminated union same key\r\n* discriminated union same key\r\n\r\n**Expected behavior:**\r\n\r\n`CatMap` should have type\r\n\r\n```ts\r\ntype CatMap = {\r\n cat: TerrestrialCat[] | AlienCat[];\r\n}\r\n```\r\n\r\n**Actual behavior:**\r\n\r\n`CatMap` has type\r\n\r\n```ts\r\ntype CatMap = {\r\n cat: AlienCat[];\r\n}\r\n```\r\n\r\n\r\n\u003c!-- Did you find other bugs that looked similar? -->\r\n**Related Issues:**\r\n\r\n**Code**\r\n```ts\r\nenum TerrestrialAnimalTypes {\r\n CAT = \"cat\",\r\n};\r\n\r\nenum AlienAnimalTypes {\r\n CAT = \"cat\",\r\n};\r\n\r\ntype AnimalTypes = TerrestrialAnimalTypes | AlienAnimalTypes;\r\n\r\ninterface TerrestrialCat {\r\n type: TerrestrialAnimalTypes.CAT;\r\n address: string;\r\n}\r\n\r\ninterface AlienCat {\r\n type: AlienAnimalTypes.CAT\r\n planet: string;\r\n}\r\n\r\ntype Cats = TerrestrialCat | AlienCat;\r\n\r\n// type A = TerrestrialCat | AlienCat\r\ntype A = Extract\u003cCats, { type: \"cat\" }>;\r\n\r\n/*\r\n * type CatMap = {\r\n * cat: AlienCat[];\r\n * }\r\n */\r\ntype CatMap = {\r\n [V in AnimalTypes]: Extract\u003cCats, { type: V }>[]\r\n};\r\n```\r\n\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Output\u003c/b>\u003c/summary>\r\n\r\n```ts\r\n\"use strict\";\r\nvar AnimalTypes;\r\n(function (AnimalTypes) {\r\n AnimalTypes[\"CAT\"] = \"cat\";\r\n})(AnimalTypes || (AnimalTypes = {}));\r\n;\r\n\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Compiler Options\u003c/b>\u003c/summary>\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictPropertyInitialization\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"useDefineForClassFields\": false,\r\n \"alwaysStrict\": true,\r\n \"allowUnreachableCode\": false,\r\n \"allowUnusedLabels\": false,\r\n \"downlevelIteration\": false,\r\n \"noEmitHelpers\": false,\r\n \"noLib\": false,\r\n \"noStrictGenericChecks\": false,\r\n \"noUnusedLocals\": false,\r\n \"noUnusedParameters\": false,\r\n \"esModuleInterop\": true,\r\n \"preserveConstEnums\": false,\r\n \"removeComments\": false,\r\n \"skipLibCheck\": false,\r\n \"checkJs\": false,\r\n \"allowJs\": false,\r\n \"declaration\": true,\r\n \"experimentalDecorators\": false,\r\n \"emitDecoratorMetadata\": false,\r\n \"target\": \"ES2017\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n**Playground Link:** [Provided](https://www.typescriptlang.org/play/#code/KYOwrgtgBAKsBO9gGcAu8CWBDANgQRAwlxgE8AHFKAbwCgoGoBhPGKAXigCIBjLVLgBpaAXwDctWqEhQ8ODKAJESFKnUbNWHbnwHDxk1KtmFiOMpWTa4iFOmz5TKy1AA+s+YqfnVyCbQwQVAQAMyweYFgEJDRMXCZ+GnpGI0oALijbWIclMwsUADoWGAkNLAATcpjkDOyQAHMJEUlA4PgwiI8FEATUJI1U4Ay5btznQuLkhnIcLBBgVFr7BqbDY16rThsY+3jE9xHQXv8AehOoQdlraLs4nF63LqP+Wku8bQBRAA90cNQAHg2ghoF1UGV4-C4UBEAD5TgAqejw0GUZj8ACyWHI2nUyIYumGnh6-AA2gBdUrI5pQeEnV7rDFYnFTKAkgBqUECJmUPksZIy31+PABQJBgwyHNh5NEYiAA)","author":{"url":"https://github.com/chenlijun99","@type":"Person","name":"chenlijun99"},"datePublished":"2020-04-09T10:25:51Z","url":"https://github.com/microsoft/TypeScript/issues/37859"}
| 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:3842fb2c-8b12-1e30-f26e-1b20873209a4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D80:28A483:602368:7F6C1B:6B01A23A |
| html-safe-nonce | 44f81843625207a842988fecbd381b1c02c1b47cde8d81f90c7a2bad1083acc0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDgwOjI4QTQ4Mzo2MDIzNjg6N0Y2QzFCOjZCMDFBMjNBIiwidmlzaXRvcl9pZCI6IjgzMzExNjUyNDA4Njc3OTE0MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 87cb05e89e76db717038fc5d685802be314920abb4d162b8febb8a5a79a22eb5 |
| hovercard-subject-tag | issue:597182438 |
| 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/37859/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dfc21a5772d3dc80e74f0fab9bba595917bd999019579f0740dd3ada217aa829/microsoft/TypeScript/issues/37859 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dfc21a5772d3dc80e74f0fab9bba595917bd999019579f0740dd3ada217aa829/microsoft/TypeScript/issues/37859 |
| og:image:alt | TypeScript Version: 3.8.3 Search Terms: map from discriminated union same key discriminated union same key Expected behavior: CatMap should have type type CatMap = { cat: TerrestrialCat[] | AlienCa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chenlijun99 |
| 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