Title: Union not narrowed with `typeof x.y` as a discriminant · Issue #32399 · microsoft/TypeScript · GitHub
Open Graph Title: Union not narrowed with `typeof x.y` as a discriminant · Issue #32399 · microsoft/TypeScript
X Title: Union not narrowed with `typeof x.y` as a discriminant · Issue #32399 · microsoft/TypeScript
Description: TypeScript Version: 3.6.0-dev.20190713 Search Terms: TS2339, union type object, union type property does not exist And github suggestions while I was writing the title. Code type Test = { someKey: false } | { someKey: { someKeyInside?: n...
Open Graph Description: TypeScript Version: 3.6.0-dev.20190713 Search Terms: TS2339, union type object, union type property does not exist And github suggestions while I was writing the title. Code type Test = { someKey: ...
X Description: TypeScript Version: 3.6.0-dev.20190713 Search Terms: TS2339, union type object, union type property does not exist And github suggestions while I was writing the title. Code type Test = { someKey: ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32399
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Union not narrowed with `typeof x.y` as a discriminant","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!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.6.0-dev.20190713\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** `TS2339`, `union type object`, `union type property does not exist`\r\nAnd github suggestions while I was writing the title.\r\n\r\n**Code**\r\n```ts\r\ntype Test = {\r\n someKey: false\r\n} | {\r\n someKey: {\r\n someKeyInside?: number\r\n },\r\n someKeyThatExistOnlyIfOtherKeyIsNotFalse: string;\r\n};\r\n\r\ndeclare const test: Test;\r\n\r\nif (typeof test.someKey === 'object') {\r\n console.log(test.someKeyThatExistOnlyIfOtherKeyIsNotFalse);\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nString in `someKeyThatExistOnlyIfOtherKeyIsNotFalse` should be logged\r\n\r\n**Actual behavior:**\r\n```\r\nerror TS2339: Property 'someKeyThatExistOnlyIfSomeKeyIsNotFalse' does not exist on type 'Test2'.\r\n Property 'someKeyThatExistOnlyIfSomeKeyIsNotFalse' does not exist on type '{ someKey: false; }'.\r\n\r\n29 console.log(test2.someKeyThatExistOnlyIfSomeKeyIsNotFalse); // TS2339: Property 'someKeyThatExistOnlyIfSomeKeyIsNotFalse' does not exist on type '{ someKey: false; }'.\r\n```\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\nhttps://www.typescriptlang.org/play/index.html#code/C4TwDgpgBAKhDOwCMUC8UDeAoKurwHsBbCAaQhAC4oAzAQwBt4IsBfKAH0xz0JPKrc8w-MTIUAkgDt4ASwAmEalICuRAEYQATj1ysANLtH8KMABZ1gAUQAesxAHkpDEBJoPgZ7QInwAcgTAAGKMzNSIWrJSAOYA3GzxWIoAxgx0WtDJBDLAUMAIyNRwiEiJsjRQABT5JQB0fOIgAJRCeFkyBAwQtQwE0dUFSPViAuaWtvbATi5uHl5aPv6BIUwQTbFQAPSbUA6kAIRsWFigkLAFAExorbgNAtT0q2ycN8aN1NgieNuwXlDZLn+Umg8nKNG0ECkyWgNC0xDy4GgxWQ+jePhkCkydCkUE0UBUUkUNCiEHkQLRFCMwjukgxigA-Mo1JodMIDEYaSAxtY7I5nK53J5vJIlsFQkp8MBIjF4qxEik0hkoO1EHlLkVLmUKtVEQQKjVgBdhiYQGhUOgAOQEdQAKwgyWAFpanza2UIXR6fQGiCNnO5Ez5M0F80WATFq3WWx2MAAyhcAMzxgCc1AACnDIFpQFALX6LDzJtMBXNha5RStmBaoPICAgoFJAlAILzctkEWcLRgKYJHswNqwLbU2EA\r\n\r\nTake a look at `type Test1`. The only one difference from `type Test2` is `someKeyInside` should be always defined.\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n-","author":{"url":"https://github.com/tusklozeleniy","@type":"Person","name":"tusklozeleniy"},"datePublished":"2019-07-15T05:02:45Z","url":"https://github.com/microsoft/TypeScript/issues/32399"}
| 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:fbc51532-3386-ac32-4780-00ebb96e604c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C54E:32405D:14774C:1C9A00:6B046F9A |
| html-safe-nonce | af61de7775db32ab2989b397db8a36c56d879a3dd60778c6f1f82867beaa1630 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTRFOjMyNDA1RDoxNDc3NEM6MUM5QTAwOjZCMDQ2RjlBIiwidmlzaXRvcl9pZCI6IjQ0OTQ1NjMwODY2OTQ2NDE1NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f8cc156bdcae53150dcc2a3ce8268de6a2a99edf55d5fc1ef1585a5b5ecd1d16 |
| hovercard-subject-tag | issue:467942096 |
| 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/32399/issue_layout |
| twitter:image | https://opengraph.githubassets.com/de93bcd371175d642e538ddf9342492dfd3e9ad9fea190bc6456c8e34a407df5/microsoft/TypeScript/issues/32399 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/de93bcd371175d642e538ddf9342492dfd3e9ad9fea190bc6456c8e34a407df5/microsoft/TypeScript/issues/32399 |
| og:image:alt | TypeScript Version: 3.6.0-dev.20190713 Search Terms: TS2339, union type object, union type property does not exist And github suggestions while I was writing the title. Code type Test = { someKey: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tusklozeleniy |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| 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 | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width