Title: Control flow narrowing sometimes de-aliases unions · Issue #42304 · microsoft/TypeScript · GitHub
Open Graph Title: Control flow narrowing sometimes de-aliases unions · Issue #42304 · microsoft/TypeScript
X Title: Control flow narrowing sometimes de-aliases unions · Issue #42304 · microsoft/TypeScript
Description: After #42149, which usually preserves the type aliases of unions as written, some type aliases end up de-aliased in control flow: (example based on @types/amap-js-api) type Direction = 'up' | 'down' | 'left' | 'right' interface Input { d...
Open Graph Description: After #42149, which usually preserves the type aliases of unions as written, some type aliases end up de-aliased in control flow: (example based on @types/amap-js-api) type Direction = 'up' | 'down...
X Description: After #42149, which usually preserves the type aliases of unions as written, some type aliases end up de-aliased in control flow: (example based on @types/amap-js-api) type Direction = 'up'...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/42304
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Control flow narrowing sometimes de-aliases unions","articleBody":"After #42149, which usually preserves the type aliases of unions as written, some type aliases end up de-aliased in control flow:\r\n(example based on `@types/amap-js-api`)\r\n\r\n```ts\r\ntype Direction = 'up' | 'down' | 'left' | 'right'\r\ninterface Input {\r\n direction?: Direction\r\n}\r\ndeclare let input: Input\r\nif (input.direction) {\r\n input.direction/*should be Direction*/\r\n}\r\n```\r\n\r\nExpected: The inner `input.direction: Direction`\r\n\r\nActual: The inner `input.direction: 'up' | 'down' | 'left' | 'right'`\r\n\r\nThis occurs because control flow narrowing uses `filterType`, which doesn't understand type aliases or attempt to preserve them. Previously the union-interning behaviour preserved the alias, but that's no longer the case.","author":{"url":"https://github.com/sandersn","@type":"Person","name":"sandersn"},"datePublished":"2021-01-12T21:53:01Z","url":"https://github.com/microsoft/TypeScript/issues/42304"}
| 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:b1d97b72-2bd0-e0fc-a4bf-c1d01c220d8e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BFF2:215B92:2720FEE:3421530:6B01AC5A |
| html-safe-nonce | d3dcea7eb4b03af279a445528c28329cf93f12956048dab3de00426455ba0f63 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkYyOjIxNUI5MjoyNzIwRkVFOjM0MjE1MzA6NkIwMUFDNUEiLCJ2aXNpdG9yX2lkIjoiNjc5OTk1MDM5OTg3ODA0ODg1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 611c2f5a9d2606a70bfafeb6ef22195bf25627d3fb34882703794103e3b26b4f |
| hovercard-subject-tag | issue:784620391 |
| 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/42304/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc8584465ebe8a12b7324718b968541dc9205dcca610609cc18ef79ec0e2b994/microsoft/TypeScript/issues/42304 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc8584465ebe8a12b7324718b968541dc9205dcca610609cc18ef79ec0e2b994/microsoft/TypeScript/issues/42304 |
| og:image:alt | After #42149, which usually preserves the type aliases of unions as written, some type aliases end up de-aliased in control flow: (example based on @types/amap-js-api) type Direction = 'up' | 'down... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sandersn |
| 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