Title: Generics do not preserve scoped union type of enums · Issue #24919 · microsoft/TypeScript · GitHub
Open Graph Title: Generics do not preserve scoped union type of enums · Issue #24919 · microsoft/TypeScript
X Title: Generics do not preserve scoped union type of enums · Issue #24919 · microsoft/TypeScript
Description: TypeScript Version: 3.0.0-dev.201xxxxx I was unable to try this. This is attempted on current playground version (2.8 or 2.9, the playground does not specify) Search Terms: NonNullable, union Code declare function test
Open Graph Description: TypeScript Version: 3.0.0-dev.201xxxxx I was unable to try this. This is attempted on current playground version (2.8 or 2.9, the playground does not specify) Search Terms: NonNullable, union Code ...
X Description: TypeScript Version: 3.0.0-dev.201xxxxx I was unable to try this. This is attempted on current playground version (2.8 or 2.9, the playground does not specify) Search Terms: NonNullable, union Code ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/24919
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generics do not preserve scoped union type of enums","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.0.0-dev.201xxxxx\r\nI was unable to try this. This is attempted on current playground version (2.8 or 2.9, the playground does not specify)\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** NonNullable, union\r\n\r\n**Code**\r\n```ts\r\ndeclare function test\u003cT>(condition: T): NonNullable\u003cT>;\r\n\r\nenum A {\r\n ONE,\r\n TWO,\r\n}\r\n\r\nfunction thing(x: A.ONE) { // or a union type of some of the enum values.\r\n if (x === A.TWO) {\r\n // x cannot be A.TWO\r\n }\r\n\r\n const y = test(x);\r\n \r\n if (y === A.TWO) {\r\n // y can be A.TWO....\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\ny should not be assignable to A.TWO. y should remain A.ONE type.\r\n\r\n**Actual behavior:**\r\ny becomes type A instead of incoming A.ONE type.\r\n\r\n**Playground Link:** \r\nhttps://www.typescriptlang.org/play/#src=declare%20function%20test%3CT%3E(condition%3A%20T)%3A%20NonNullable%3CT%3E%3B%0D%0A%0D%0Aenum%20A%20%7B%0D%0A%20%20ONE%2C%0D%0A%20%20TWO%2C%0D%0A%7D%0D%0A%0D%0Afunction%20thing(x%3A%20A.ONE)%20%7B%0D%0A%20%20if%20(x%20%3D%3D%3D%20A.TWO)%20%7B%0D%0A%20%20%20%20%2F%2F%20x%20cannot%20be%20A.TWO%0D%0A%20%20%7D%0D%0A%20%20const%20y%20%3D%20test(x)%3B%0D%0A%20%20%0D%0A%20%20if%20(y%20%3D%3D%3D%20A.TWO)%20%7B%0D%0A%20%20%20%20%2F%2F%20y%20can%20be%20A.TWO....%0D%0A%20%20%7D%0D%0A%7D%0D%0A\r\n\r\n**Related Issues:** #23884 #23046\r\n\r\nThanks for taking a look!","author":{"url":"https://github.com/trshafer","@type":"Person","name":"trshafer"},"datePublished":"2018-06-13T01:03:30Z","url":"https://github.com/microsoft/TypeScript/issues/24919"}
| 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:25dd247d-f6f5-4c4b-592c-6ceb1d969ca9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD3C:EDA7A:869189:AC8AAA:6B00EA6B |
| html-safe-nonce | dd5bb05e57a684f5ea66e1a43bad6b05af6d68356c08dc6080dc744898b68078 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDNDOkVEQTdBOjg2OTE4OTpBQzhBQUE6NkIwMEVBNkIiLCJ2aXNpdG9yX2lkIjoiNDY3NTMxMDk4Mjg0NTc1Mzk2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5c49c48f899eb33c3946295104e6760cfea27403be9afaac4829a0467d8e73cd |
| hovercard-subject-tag | issue:331805116 |
| 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/24919/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6b754361411ecaf3795aefdebdf468fa2e37f878ca55de4c05e732b439aa54e4/microsoft/TypeScript/issues/24919 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6b754361411ecaf3795aefdebdf468fa2e37f878ca55de4c05e732b439aa54e4/microsoft/TypeScript/issues/24919 |
| og:image:alt | TypeScript Version: 3.0.0-dev.201xxxxx I was unable to try this. This is attempted on current playground version (2.8 or 2.9, the playground does not specify) Search Terms: NonNullable, union Code ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trshafer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width