Title: Index key accessed nullable index type is not narrowed from nullable · Issue #12636 · microsoft/TypeScript · GitHub
Open Graph Title: Index key accessed nullable index type is not narrowed from nullable · Issue #12636 · microsoft/TypeScript
X Title: Index key accessed nullable index type is not narrowed from nullable · Issue #12636 · microsoft/TypeScript
Description: interface S { hello: any; } interface R { [i: string]: S | undefined; } function f
Open Graph Description: interface S { hello: any; } interface R { [i: string]: S | undefined; } function f
X Description: interface S { hello: any; } interface R { [i: string]: S | undefined; } function f<K extends keyof R>(p: K) { let r: R = {}; if (r[p]) { r[p].hello // Error: hello does not exists on type R[K...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12636
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Index key accessed nullable index type is not narrowed from nullable","articleBody":"```ts\r\ninterface S {\r\n hello: any;\r\n}\r\n\r\ninterface R {\r\n [i: string]: S | undefined;\r\n}\r\n\r\nfunction f\u003cK extends keyof R>(p: K) {\r\n let r: R = {};\r\n if (r[p]) {\r\n r[p].hello // Error: hello does not exists on type R[K]\r\n }\r\n}\r\n```\r\nRemoving the type `undefined` from `S | undefined` fixes the error and also the `if` check is no longer required.","author":{"url":"https://github.com/tinganho","@type":"Person","name":"tinganho"},"datePublished":"2016-12-03T14:34:55Z","url":"https://github.com/microsoft/TypeScript/issues/12636"}
| 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:aa05feb7-61c1-428a-068a-db9e236a2c66 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E0E:327701:92D9C:C8345:6B04AF5E |
| html-safe-nonce | 71557a4922b3c36ca8832d8b9e6dc3b551994f8028584ae2e0a7becf8f67e3b6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTBFOjMyNzcwMTo5MkQ5QzpDODM0NTo2QjA0QUY1RSIsInZpc2l0b3JfaWQiOiI4Mjk3MjE5NzIyMDMwOTE5NTE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 119292f1c20d51bee0d42ac7947339ccaf374b2d5ab9fe9438cc5284e7dae03b |
| hovercard-subject-tag | issue:193290270 |
| 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/12636/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d73e70cc01b67603a57ecae5096cd6f09f66eee5b5c152ca3efbd4a16b962fb5/microsoft/TypeScript/issues/12636 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d73e70cc01b67603a57ecae5096cd6f09f66eee5b5c152ca3efbd4a16b962fb5/microsoft/TypeScript/issues/12636 |
| og:image:alt | interface S { hello: any; } interface R { [i: string]: S | undefined; } function f |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tinganho |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| 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 | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| 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