Title: Values are not assignable to deferred conditional types even when they are assignable to both branches. · Issue #41009 · microsoft/TypeScript · GitHub
Open Graph Title: Values are not assignable to deferred conditional types even when they are assignable to both branches. · Issue #41009 · microsoft/TypeScript
X Title: Values are not assignable to deferred conditional types even when they are assignable to both branches. · Issue #41009 · microsoft/TypeScript
Description: TypeScript Version: 4.1.0-dev.20201009 & 4.0.3 Search Terms: deferred conditional assignment not assignable to type Code const doSomething =
Open Graph Description: TypeScript Version: 4.1.0-dev.20201009 & 4.0.3 Search Terms: deferred conditional assignment not assignable to type Code const doSomething =
X Description: TypeScript Version: 4.1.0-dev.20201009 & 4.0.3 Search Terms: deferred conditional assignment not assignable to type Code const doSomething = <T extends boolean>(t: T) => { const a: str...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/41009
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Values are not assignable to deferred conditional types even when they are assignable to both branches.","articleBody":"**TypeScript Version:** 4.1.0-dev.20201009 & 4.0.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:** deferred conditional assignment not assignable to type\r\n\r\n**Code**\r\n\r\n```ts\r\nconst doSomething = \u003cT extends boolean>(t: T) => {\r\n const a: string = 'foo';\r\n const b: string | undefined = 'bar';\r\n const c: T extends true ? string : (string | undefined) = 'baz' as string;\r\n return c;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n(`baz` as string) is assignable to `c` as `string` is assignable to both branches of the deferred conditional type. \r\n\r\n**Actual behavior:**\r\n\r\nThe following error is emitted:\r\n\r\n```\r\nType 'string' is not assignable to type 'T extends true ? string : string | undefined'.ts(2322)\r\n```\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play?ts=4.1.0-dev.20201009#code/FAYw9gdgzgLgBAEzAZTAWwKYwBYEsIDmcAvHADwAqcGAHjBhAlHAEZhgA2GAhhAHwAKGAC44FAJQk+cAN7A4ccNHjdRsAE74ipAOQAzdjoDc8xZFis1MTYTgAfOAFdGGPfgwIScHS27rjpkoWIKJUtPSMzNaOGHAA-HAaWnCiAkm2Ds4Iru4Ikrq+AF4BCupYjuoQiiYAvkA\r\n\r\n**Related Issues:** #39364 #39577\r\n","author":{"url":"https://github.com/s0","@type":"Person","name":"s0"},"datePublished":"2020-10-09T14:26:59Z","url":"https://github.com/microsoft/TypeScript/issues/41009"}
| 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:b6908d03-215e-6458-68fa-2c6ea2b0734a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8AFC:EDA7A:278F210:32437A8:6B0199E8 |
| html-safe-nonce | 3f2fec23ce07cd3784674f33e78a7853b34f7efa27cd3832ded021603bbbfbc6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUZDOkVEQTdBOjI3OEYyMTA6MzI0MzdBODo2QjAxOTlFOCIsInZpc2l0b3JfaWQiOiIyMTk1Njc0NDE1NTEyMDAxMDAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 88302621d6ed9afb969c918ac04c61d70ada4919b3088b6889b4eb6f46663b76 |
| hovercard-subject-tag | issue:718191724 |
| 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/41009/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c61283d6ceb578b074e5f187007aad75f07e8f1620a0b12a559ce875d2b6b6a6/microsoft/TypeScript/issues/41009 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c61283d6ceb578b074e5f187007aad75f07e8f1620a0b12a559ce875d2b6b6a6/microsoft/TypeScript/issues/41009 |
| og:image:alt | TypeScript Version: 4.1.0-dev.20201009 & 4.0.3 Search Terms: deferred conditional assignment not assignable to type Code const doSomething = |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | s0 |
| 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