Title: Unknown types narrowed to a union won't narrow further · Issue #30557 · microsoft/TypeScript · GitHub
Open Graph Title: Unknown types narrowed to a union won't narrow further · Issue #30557 · microsoft/TypeScript
X Title: Unknown types narrowed to a union won't narrow further · Issue #30557 · microsoft/TypeScript
Description: This fails on the playground, and I believe it also fails on typescript@3.4.0-dev.20190323 TypeScript Version: typescript@3.4.0-dev.20190323 Search Terms: unknown intersection failure types narrow Code interface TypeA { Name: "TypeA"; Va...
Open Graph Description: This fails on the playground, and I believe it also fails on typescript@3.4.0-dev.20190323 TypeScript Version: typescript@3.4.0-dev.20190323 Search Terms: unknown intersection failure types narrow ...
X Description: This fails on the playground, and I believe it also fails on typescript@3.4.0-dev.20190323 TypeScript Version: typescript@3.4.0-dev.20190323 Search Terms: unknown intersection failure types narrow ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/30557
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unknown types narrowed to a union won't narrow further","articleBody":"This fails [on the playground](https://www.typescriptlang.org/play/#src=interface%20TypeA%20%7B%0A%09Name%3A%20%22TypeA%22%3B%0A%09Value1%3A%20%22Cool%20stuff!%22%3B%0A%7D%0A%0Ainterface%20TypeB%20%7B%0A%09Name%3A%20%22TypeB%22%3B%0A%09Value2%3A%200%3B%0A%7D%0A%0Atype%20Type%20%3D%20TypeA%20%7C%20TypeB%3B%0A%0Adeclare%20function%20isType(x%3A%20unknown)%3A%20x%20is%20Type%3B%0A%0Afunction%20WorksProperly(data%3A%20Type)%20%7B%0A%09if%20(data.Name%20%3D%3D%3D%20%22TypeA%22)%20%7B%0A%09%09%2F%2F%20data%3A%20TypeA%0A%09%09const%20value1%20%3D%20data.Value1%3B%0A%09%7D%0A%7D%0A%0Afunction%20DoesNotWork(data%3A%20unknown)%20%7B%0A%09if%20(isType(data))%20%7B%0A%09%09if%20(data.Name%20%3D%3D%3D%20%22TypeA%22)%20%7B%0A%09%09%09%2F%2F%20data%3A%20Type%0A%09%09%09%2F%2F%20data%20should%20be%20TypeA%0A%09%09%09const%20value1%20%3D%20data.Value1%3B%0A%09%09%7D%0A%09%7D%0A%7D%0A), and I believe it also fails on typescript@3.4.0-dev.20190323\r\n\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!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** typescript@3.4.0-dev.20190323\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** unknown intersection failure types narrow\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface TypeA {\r\n\tName: \"TypeA\";\r\n\tValue1: \"Cool stuff!\";\r\n}\r\n\r\ninterface TypeB {\r\n\tName: \"TypeB\";\r\n\tValue2: 0;\r\n}\r\n\r\ntype Type = TypeA | TypeB;\r\n\r\ndeclare function isType(x: unknown): x is Type;\r\n\r\nfunction WorksProperly(data: Type) {\r\n\tif (data.Name === \"TypeA\") {\r\n\t\t// data: TypeA\r\n\t\tconst value1 = data.Value1;\r\n\t}\r\n}\r\n\r\nfunction DoesNotWork(data: unknown) {\r\n\tif (isType(data)) {\r\n\t\tif (data.Name === \"TypeA\") {\r\n\t\t\t// data: Type\r\n\t\t\t// data should be TypeA\r\n\t\t\tconst value1 = data.Value1; // type error!\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Expected behavior:** in `DoesNotWork`, `data` should be TypeA after we can guarentee it is named \"TypeA\"\r\n\r\n**Actual behavior:** `data` is still only a `Type`\r\n\r\n[**Playground Link:** Here](https://www.typescriptlang.org/play/#src=interface%20TypeA%20%7B%0A%09Name%3A%20%22TypeA%22%3B%0A%09Value1%3A%20%22Cool%20stuff!%22%3B%0A%7D%0A%0Ainterface%20TypeB%20%7B%0A%09Name%3A%20%22TypeB%22%3B%0A%09Value2%3A%200%3B%0A%7D%0A%0Atype%20Type%20%3D%20TypeA%20%7C%20TypeB%3B%0A%0Adeclare%20function%20isType(x%3A%20unknown)%3A%20x%20is%20Type%3B%0A%0Afunction%20WorksProperly(data%3A%20Type)%20%7B%0A%09if%20(data.Name%20%3D%3D%3D%20%22TypeA%22)%20%7B%0A%09%09%2F%2F%20data%3A%20TypeA%0A%09%09const%20value1%20%3D%20data.Value1%3B%0A%09%7D%0A%7D%0A%0Afunction%20DoesNotWork(data%3A%20unknown)%20%7B%0A%09if%20(isType(data))%20%7B%0A%09%09if%20(data.Name%20%3D%3D%3D%20%22TypeA%22)%20%7B%0A%09%09%09%2F%2F%20data%3A%20Type%0A%09%09%09%2F%2F%20data%20should%20be%20TypeA%0A%09%09%09const%20value1%20%3D%20data.Value1%3B%0A%09%09%7D%0A%09%7D%0A%7D%0A)\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? --> I looked through several pages of issues and did not find anything similar.\r\n","author":{"url":"https://github.com/Validark","@type":"Person","name":"Validark"},"datePublished":"2019-03-23T14:38:07Z","url":"https://github.com/microsoft/TypeScript/issues/30557"}
| 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:febdb908-2459-f57d-a5b7-903199f1c7fd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A802:11EACE:D42A56:11BFB69:6B01007B |
| html-safe-nonce | 7ad32e5fa05fb530e807034605cdea836656a6e3da71d0b78defcd6122c3a200 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODAyOjExRUFDRTpENDJBNTY6MTFCRkI2OTo2QjAxMDA3QiIsInZpc2l0b3JfaWQiOiI1NjkyMjM5MTI1NDgzMTU5Njc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5b19b34590abb17b33414c612ddd0c5f4a468db7b26cde777db537655db3204f |
| hovercard-subject-tag | issue:424507245 |
| 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/30557/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c1414cd70095f039006cdc4338455685c5fcb01f4e683ef4a9ee1c0f3c71292c/microsoft/TypeScript/issues/30557 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c1414cd70095f039006cdc4338455685c5fcb01f4e683ef4a9ee1c0f3c71292c/microsoft/TypeScript/issues/30557 |
| og:image:alt | This fails on the playground, and I believe it also fails on typescript@3.4.0-dev.20190323 TypeScript Version: typescript@3.4.0-dev.20190323 Search Terms: unknown intersection failure types narrow ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Validark |
| 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