Title: Assertions do not narrow types when used as operand of the comma operator. · Issue #41264 · microsoft/TypeScript · GitHub
Open Graph Title: Assertions do not narrow types when used as operand of the comma operator. · Issue #41264 · microsoft/TypeScript
X Title: Assertions do not narrow types when used as operand of the comma operator. · Issue #41264 · microsoft/TypeScript
Description: TypeScript Version: 4.1.0-dev.20201026 Search Terms: assert comma operator Code foo1 and foo2 should be equivalent but the assertion in foo2 does not narrow they typing of param. declare function assert(value: any): asserts value; functi...
Open Graph Description: TypeScript Version: 4.1.0-dev.20201026 Search Terms: assert comma operator Code foo1 and foo2 should be equivalent but the assertion in foo2 does not narrow they typing of param. declare function a...
X Description: TypeScript Version: 4.1.0-dev.20201026 Search Terms: assert comma operator Code foo1 and foo2 should be equivalent but the assertion in foo2 does not narrow they typing of param. declare function a...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/41264
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Assertions do not narrow types when used as operand of the comma operator.","articleBody":"\u003c!-- 🚨 STOP 🚨 STOP 🚨 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--\u003e\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n--\u003e\r\n**TypeScript Version:** 4.1.0-dev.20201026\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) --\u003e\r\n**Search Terms:** assert comma operator\r\n\r\n**Code**\r\n\r\n`foo1` and `foo2` should be equivalent but the assertion in `foo2` does not narrow they typing of `param`.\r\n\r\n```ts\r\ndeclare function assert(value: any): asserts value;\r\n\r\nfunction foo1(param: number | null | undefined): number | null { \r\n const val = param !== undefined;\r\n\r\n if (val) {\r\n assert(param !== undefined);\r\n return param\r\n } else {\r\n return null;\r\n }\r\n}\r\n\r\nfunction foo2(param: number | null | undefined): number | null { \r\n const val = param !== undefined;\r\n return val ? (assert(param !== undefined), param) : null;\r\n // ^^^^^ Still typed as number | null | undefined\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo errors.\r\n\r\n**Actual behavior:**\r\n\r\n```\r\nType 'number | null | undefined' is not assignable to type 'number | null'.\r\n Type 'undefined' is not assignable to type 'number | null'.(2322)\r\n```\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play?ts=4.1.0-dev.20201026#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXygGdCQYMAKANygmRAC4DUBPASkaJLMPmtpADcAWABQolOmx4kOHAEZyAB1hQAto1TJVAI1LwAPvE0QIB+GlCIsqEMHZGtumGeOmA3vFHx4YPIQy8NPAAvPDKMGrwAITBoRYgVjbAwmIi3liI8FQ0rPBuXt4ExKQU4ZExcaiW1rasKYXwcBjIMPhlqgUAvvAgECR5Bd5NLfiu9fCdopOpEpi4+IiyAExKKuoOOnqGrmbxibUajlsOJnmeaT5+AXwhYWvRseZVCTXJBcOtgaYA-FmcJasIqoHpVqklWAAaO5A3KHEzjBqIpHIlGo+AAenR8AAerjcfAAMrYU4YZiKWxFDZOFzIU6GPavKZAA\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? --\u003e\r\n","author":{"url":"https://github.com/RebeccaStevens","@type":"Person","name":"RebeccaStevens"},"datePublished":"2020-10-27T02:27:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/41264/TypeScript/issues/41264"}
| 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:79262791-2753-5c4d-cfa9-06f5c0562c37 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DDA2:1F16:47F9AA2:65DCCA6:6A506456 |
| html-safe-nonce | 704df13179828db53f494f334d3c9e7a808a091025facf7fa9b790e597a58c6d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREEyOjFGMTY6NDdGOUFBMjo2NURDQ0E2OjZBNTA2NDU2IiwidmlzaXRvcl9pZCI6IjcxMTc0NzQxOTI0Mzg2MTcxNzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5ee375e569dcde350b80eb12f10ab058290e98866df3288ff8c22d2fcd76c1cd |
| hovercard-subject-tag | issue:730046486 |
| 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/41264/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5f8b697ef097585150fe113697c7a5ee871d5d589bd7b4a267ddb81f35735cfe/microsoft/TypeScript/issues/41264 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5f8b697ef097585150fe113697c7a5ee871d5d589bd7b4a267ddb81f35735cfe/microsoft/TypeScript/issues/41264 |
| og:image:alt | TypeScript Version: 4.1.0-dev.20201026 Search Terms: assert comma operator Code foo1 and foo2 should be equivalent but the assertion in foo2 does not narrow they typing of param. declare function a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RebeccaStevens |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| 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 | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width