Title: Generic lookup type wrongly narrowed to `never` with strictNullChecks · Issue #26130 · microsoft/TypeScript · GitHub
Open Graph Title: Generic lookup type wrongly narrowed to `never` with strictNullChecks · Issue #26130 · microsoft/TypeScript
X Title: Generic lookup type wrongly narrowed to `never` with strictNullChecks · Issue #26130 · microsoft/TypeScript
Description: I ran across this while migrating my project to strictNullChecks and it's positively bizarre. TypeScript Version: master (50f442f) Search Terms: mapped type narrow narrowing null strictNullChecks never Code (with strictNullChecks) let ma...
Open Graph Description: I ran across this while migrating my project to strictNullChecks and it's positively bizarre. TypeScript Version: master (50f442f) Search Terms: mapped type narrow narrowing null strictNullChecks n...
X Description: I ran across this while migrating my project to strictNullChecks and it's positively bizarre. TypeScript Version: master (50f442f) Search Terms: mapped type narrow narrowing null strictNullChec...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26130
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic lookup type wrongly narrowed to `never` with strictNullChecks","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\nI ran across this while migrating my project to `strictNullChecks` and it's positively bizarre.\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** master (50f442f)\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** mapped type narrow narrowing null strictNullChecks never\r\n\r\n**Code** (with `strictNullChecks`)\r\n\r\n```ts\r\nlet mappedObject: {[K in \"foo\"]: null | {x: string}} = {foo: {x: \"hello\"}};\r\ndeclare function foo\u003cT>(x: T): null | T;\r\n\r\nfunction bar\u003cK extends \"foo\">(key: K) {\r\n const element = foo(mappedObject[key]);\r\n if (element == null)\r\n return;\r\n const x = element.x;\r\n}\r\n```\r\n\r\n**Expected behavior:** Compile without error.\r\n\r\n**Actual behavior:** Error: Property 'x' does not exist on type 'never'.\r\n\r\n**Playground Link:** [link](https://www.typescriptlang.org/play/#src=let%20mappedObject%3A%20%7B%5BK%20in%20%22foo%22%5D%3A%20null%20%7C%20%7Bx%3A%20string%7D%7D%20%3D%20%7Bfoo%3A%20%7Bx%3A%20%22hello%22%7D%7D%3B%0D%0Adeclare%20function%20foo%3CT%3E(x%3A%20T)%3A%20null%20%7C%20T%3B%0D%0A%0D%0Afunction%20bar%3CK%20extends%20%22foo%22%3E(key%3A%20K)%20%7B%0D%0A%20%20const%20element%20%3D%20foo(mappedObject%5Bkey%5D)%3B%0D%0A%20%20if%20(element%20%3D%3D%20null)%0D%0A%20%20%20%20return%3B%0D%0A%20%20const%20x%20%3D%20element.x%3B%0D%0A%7D%0D%0A) (remember to enable strictNullChecks)\r\n\r\n**Related Issues:** Didn't find any.\r\n","author":{"url":"https://github.com/mattmccutchen","@type":"Person","name":"mattmccutchen"},"datePublished":"2018-08-01T21:39:06Z","url":"https://github.com/microsoft/TypeScript/issues/26130"}
| 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:f7348cd2-7ac7-7b6a-ae51-06998d00c436 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A652:213839:2C2BFB1:3876419:6B01A710 |
| html-safe-nonce | ee0d2502770b4c9919446b819a3b7e915e5a90a8a6b3d713db22305c3df2f642 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjUyOjIxMzgzOToyQzJCRkIxOjM4NzY0MTk6NkIwMUE3MTAiLCJ2aXNpdG9yX2lkIjoiNzEwNjk5MTE5OTQ4MjkxNDU3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dcf13f1d6f237d172876d0ad8bccf5d1bd3c7f6287f9cff0367a864d4a3868ae |
| hovercard-subject-tag | issue:346779348 |
| 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/26130/issue_layout |
| twitter:image | https://opengraph.githubassets.com/674dd74d6347acce93e1ab8d56bf4b2b4627e4c5b1dc112c78ac6b1989cae4bd/microsoft/TypeScript/issues/26130 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/674dd74d6347acce93e1ab8d56bf4b2b4627e4c5b1dc112c78ac6b1989cae4bd/microsoft/TypeScript/issues/26130 |
| og:image:alt | I ran across this while migrating my project to strictNullChecks and it's positively bizarre. TypeScript Version: master (50f442f) Search Terms: mapped type narrow narrowing null strictNullChecks n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mattmccutchen |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width