Title: Conditional types are evaluated too eagerly · Issue #34810 · microsoft/TypeScript · GitHub
Open Graph Title: Conditional types are evaluated too eagerly · Issue #34810 · microsoft/TypeScript
X Title: Conditional types are evaluated too eagerly · Issue #34810 · microsoft/TypeScript
Description: TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: conditional type eager, conditional type narrowing Code type FooHelper
Open Graph Description: TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: conditional type eager, conditional type narrowing Code type FooHelper
X Description: TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: conditional type eager, conditional type narrowing Code type FooHelper<X> = (arg1: X, arg2: X extends 0 ? number : string) => void; typ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/34810
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conditional types are evaluated too eagerly","articleBody":"\r\n**TypeScript Version:** 3.7.x-dev.201xxxxx\r\n\r\n**Search Terms:** conditional type eager, conditional type narrowing\r\n\r\n**Code**\r\n\r\n```ts\r\ntype FooHelper\u003cX\u003e = (arg1: X, arg2: X extends 0 ? number : string) =\u003e void;\r\ntype Foo = FooHelper\u003c0 | 1\u003e;\r\n\r\nlet x: number;\r\nconst foo: Foo = (t, d) =\u003e {\r\n if(t === 0) { x = d; }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nNo errors, `t` has type `0 | 1` in the function body which gets narrowed to just `0` in the body of the if statement. In the if statement, `d` should have type number, because we know that `t` has to have type `0`.\r\n\r\n**Actual behavior:**\r\nType 'string | number' is not assignable to type 'string'.\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/?ts=3.7-Beta#code/C4TwDgpgBAYg9nAEhANpATgHgBoD4oC8UAFAIboDmAjAFxTYA0U5FATHdlBAB7AQB2AEwDOUAAxQA-FGHB0AS34UodfgFcAtgCMI6AJSF8ANzjzBAbgBQoSLASE7SVBkwSAPlCq4rllBGBQ3HSyCkpWAMZw-LJQAGYIdPBwDsTATIIGBPgA3pZQ+VDysamEBERiBtmBDhZQAL6WdUA\r\n\r\n**Related Issues:** not really\r\n","author":{"url":"https://github.com/jvanbruegge","@type":"Person","name":"jvanbruegge"},"datePublished":"2019-10-29T21:13:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/34810/TypeScript/issues/34810"}
| 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:8b828730-0e11-6125-43d9-1a9e437dae02 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EBAE:385126:8E7BFB:CCAD27:6A637CA4 |
| html-safe-nonce | 5074306da9f6a279cd35257298d6b271b4812b2f5a9f10849e010f8c7a8ba8b3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkFFOjM4NTEyNjo4RTdCRkI6Q0NBRDI3OjZBNjM3Q0E0IiwidmlzaXRvcl9pZCI6Ijg3Njg2Mzk4NzIyMDk3NDcxMDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c041c8e63d8ec55da2649c8396bc70b29e296b88869d14d3e7c6452d850d7deb |
| hovercard-subject-tag | issue:514228137 |
| 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/34810/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78600ae19a1c57054acb0405fb87208192c2bb94707c6a01f9e0814134213202/microsoft/TypeScript/issues/34810 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78600ae19a1c57054acb0405fb87208192c2bb94707c6a01f9e0814134213202/microsoft/TypeScript/issues/34810 |
| og:image:alt | TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: conditional type eager, conditional type narrowing Code type FooHelper |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jvanbruegge |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4c1de337de00c7969335f8866af41463301071379a3a15fba12e9b85aa6378d6 |
| 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 | a4df32552e4c631011bdcd4c81cc3d7408664a8b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width