Title: For loop wrong indexer type recognition · Issue #37639 · microsoft/TypeScript · GitHub
Open Graph Title: For loop wrong indexer type recognition · Issue #37639 · microsoft/TypeScript
X Title: For loop wrong indexer type recognition · Issue #37639 · microsoft/TypeScript
Description: Seems that indexer type could be better recognized in for loop. Please check the code. TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: mapped type, keyof Code type SimpleType = { a: string, b: number } let x: SimpleType = { a: "", b...
Open Graph Description: Seems that indexer type could be better recognized in for loop. Please check the code. TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: mapped type, keyof Code type SimpleType = { a: string, b:...
X Description: Seems that indexer type could be better recognized in for loop. Please check the code. TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: mapped type, keyof Code type SimpleType = { a: string, b:...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/37639
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"For loop wrong indexer type recognition","articleBody":"\r\nSeems that indexer type could be better recognized in for loop. Please check the code.\r\n**TypeScript Version:** 3.7.x-dev.201xxxxx\r\n\r\n**Search Terms:**\r\nmapped type, keyof \r\n**Code**\r\n\r\n```ts\r\ntype SimpleType = { a: string, b: number }\r\nlet x: SimpleType = { a: \"\", b: 9 }\r\nlet fields: (keyof SimpleType)[] = [\"a\"]\r\nfor (const f of fields) {\r\n x[f] = x[f] // This throws TS 2322, although the type is obviously the same\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nThe type of x[f] is the same as the x[f] and should be assignable. \r\n**Actual behavior:**\r\nx[f] is not assignable to x[f]\r\n**Playground Link:** \r\n[example](https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=7&pc=1#code/C4TwDgpgBAyglgWzAGwgFXNAvFA3lAQwC4oBnYAJzgDsBzAGigCMTqBXBJiCqAXwChUwKAA8S8JKgyQoOfMSgAiRYxZQAnH0ERhAMzgRkAE1IkAFAGsIIAPa7YiFOkwBKANoBdWVDeKCij35dGx4zAGMbanIoezsYg2NSFzx+KDTRN10vHBFMwIEgA)\r\n\r\n**Related Issues:** \r\nActually the initial issue was with mapped type, but while looking for the cause and workaround I created this simple showcase. Suppose fixing this would resolve mapped type issue.","author":{"url":"https://github.com/k4hvd1","@type":"Person","name":"k4hvd1"},"datePublished":"2020-03-27T09:13:12Z","url":"https://github.com/microsoft/TypeScript/issues/37639"}
| 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:2a972cac-87de-4c31-095d-555a579ba6d6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CED6:317608:82A431:A73B30:6B00E7A4 |
| html-safe-nonce | ff1cc3920117fdc58c28f3875e529cb9d05f76653f122eff6c4dd222ff897564 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUQ2OjMxNzYwODo4MkE0MzE6QTczQjMwOjZCMDBFN0E0IiwidmlzaXRvcl9pZCI6IjQwMzU4MTkwNTU3Mzc3OTI0MjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e31ef9b810ef1f9adf99b8fbee3809792bfa1af832e0ea59b39d16ab3f14f9dc |
| hovercard-subject-tag | issue:588992200 |
| 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/37639/issue_layout |
| twitter:image | https://opengraph.githubassets.com/db51eb3b9514310d772f4e92b1e5a0eee367e600c4c0bb81074086ca25522d48/microsoft/TypeScript/issues/37639 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/db51eb3b9514310d772f4e92b1e5a0eee367e600c4c0bb81074086ca25522d48/microsoft/TypeScript/issues/37639 |
| og:image:alt | Seems that indexer type could be better recognized in for loop. Please check the code. TypeScript Version: 3.7.x-dev.201xxxxx Search Terms: mapped type, keyof Code type SimpleType = { a: string, b:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | k4hvd1 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width