Title: Inferred type symbol in conditional type should be visible-but-banned in falsy arm · Issue #22610 · microsoft/TypeScript · GitHub
Open Graph Title: Inferred type symbol in conditional type should be visible-but-banned in falsy arm · Issue #22610 · microsoft/TypeScript
X Title: Inferred type symbol in conditional type should be visible-but-banned in falsy arm · Issue #22610 · microsoft/TypeScript
Description: Currently if you write type C
Open Graph Description: Currently if you write type C
X Description: Currently if you write type C<T> = T extends infer U ? U : U; // ~ Cannot find name "U" We give you an error because U is not in scope at all in the false arm. This is a) confusing ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22610
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inferred type symbol in conditional type should be visible-but-banned in falsy arm","articleBody":"Currently if you write\r\n```ts\r\ntype C\u003cT> = T extends infer U ? U : U;\r\n// ~ Cannot find name \"U\"\r\n```\r\nWe give you an error because `U` is not in scope at all in the false arm.\r\n\r\nThis is a) confusing (`U` is right there!) and b) a landmine, because you might have an outer type of the same name\r\n```ts\r\n// Elsewhere\r\ntype U = string;\r\n// ...\r\n/// Not what I meant!\r\ntype C\u003cT> = T extends infer U ? number : U;\r\n```\r\n\r\nWe should keep `U` in scope in both cases and disallow its use with an explicit error message, e.g. (please bikeshed):\r\n\r\n > Inferred type parameter \"U\" is unmatched in this case and cannot be used\r\n\r\nThis should *not* block nesting of lexical scopes; i.e. this should still be legal because each `U` would shadow the outer expression's:\r\n```ts\r\ntype C\u003cT> = T extends Array\u003cinfer U> ? U :\r\n T extends Promise\u003cinfer U> ? U :\r\n never;\r\n```","author":{"url":"https://github.com/RyanCavanaugh","@type":"Person","name":"RyanCavanaugh"},"datePublished":"2018-03-15T19:49:07Z","url":"https://github.com/microsoft/TypeScript/issues/22610"}
| 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:67491bd3-2aad-b1ee-78a1-dcb01846f92f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8380:241F93:11824C6:189BC17:6B0451F3 |
| html-safe-nonce | f7037824ab75298e4ceadec86798f7c1901eb59a978997b2f74535d9ee53d79f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzgwOjI0MUY5MzoxMTgyNEM2OjE4OUJDMTc6NkIwNDUxRjMiLCJ2aXNpdG9yX2lkIjoiNDAwMDIxODI2MDgwMDAzMzI2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3634a8e3d44d84dba482331993fe81d328d353bad1de69dc9c8af8a3fb51cd34 |
| hovercard-subject-tag | issue:305695773 |
| 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/22610/issue_layout |
| twitter:image | https://opengraph.githubassets.com/665c4890ebd48a42ef94ccebca0b4501ac091a6b4897b4f03bd06fdbf5412cc3/microsoft/TypeScript/issues/22610 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/665c4890ebd48a42ef94ccebca0b4501ac091a6b4897b4f03bd06fdbf5412cc3/microsoft/TypeScript/issues/22610 |
| og:image:alt | Currently if you write type C |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RyanCavanaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0 |
| 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 | e086f9b7e88322eb2b41885a6ad425b215737fa5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width