Title: Enum lookup for map type [P in Enum] gives "implicit any index" error · Issue #19546 · microsoft/TypeScript · GitHub
Open Graph Title: Enum lookup for map type [P in Enum] gives "implicit any index" error · Issue #19546 · microsoft/TypeScript
X Title: Enum lookup for map type [P in Enum] gives "implicit any index" error · Issue #19546 · microsoft/TypeScript
Description: TypeScript Version: 2.5.3 It could be I stumbled on something I simply don't understand, but it seems like this should work: Code enum Color { RED = "RED", BLUE = "BLUE", GREEN = "GREEN" } type ColorMap = { [P in Color]: number; // type ...
Open Graph Description: TypeScript Version: 2.5.3 It could be I stumbled on something I simply don't understand, but it seems like this should work: Code enum Color { RED = "RED", BLUE = "BLUE", GREEN = "GREEN" } type Col...
X Description: TypeScript Version: 2.5.3 It could be I stumbled on something I simply don't understand, but it seems like this should work: Code enum Color { RED = "RED", BLUE = "BLUE", GR...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/19546
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enum lookup for map type [P in Enum] gives \"implicit any index\" error","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 2.5.3\r\n\r\nIt could be I stumbled on something I simply don't understand, but it seems like this should work:\r\n\r\n**Code**\r\n\r\n```ts\r\nenum Color {\r\n RED = \"RED\",\r\n BLUE = \"BLUE\",\r\n GREEN = \"GREEN\"\r\n}\r\n\r\ntype ColorMap = {\r\n [P in Color]: number; // type ColorMap = { RED: number; BLUE: number; GREEN: number; }\r\n}\r\n\r\ndeclare const color: Color;\r\nmap[color] // Error: Element implicitly has an 'any' type because type 'ColorMap' has no index signature.\r\n```\r\n\r\nAll of the following work:\r\n\r\n```ts\r\ndeclare const map: ColorMap;\r\nmap[Color.RED] // OK\r\n\r\nconst red: Color = Color.RED;\r\nmap[red] // OK\r\n\r\ndeclare const color: keyof typeof Color;\r\nmap[color] // OK -- I don't know why this works\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n`map[color]` to work and give return type of `number`\r\n\r\n**Actual behavior:**\r\n\r\n`map[color] // Error: Element implicitly has an 'any' type because type 'ColorMap' has no index `","author":{"url":"https://github.com/aaronbeall","@type":"Person","name":"aaronbeall"},"datePublished":"2017-10-28T04:24:49Z","url":"https://github.com/microsoft/TypeScript/issues/19546"}
| 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:7ddd7eea-7a93-4257-33f4-c8e55f6bd23d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93F6:436BB:49ED19:658A6A:6B047043 |
| html-safe-nonce | 11f19ac7706bad57cbf9450386819e6115cb374541d5c92cee61599f546726de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0Y2OjQzNkJCOjQ5RUQxOTo2NThBNkE6NkIwNDcwNDMiLCJ2aXNpdG9yX2lkIjoiNTAzMTA5MjMyNTQ1NjMxMDMzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f0be150a61f4e78082b780172a77f2b34a43f94744a311ea10bd96d8cf11461d |
| hovercard-subject-tag | issue:269282342 |
| 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/19546/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e0bb9f325571216dea8c40026b7dd843c420a9b4c7910dcd3eb0ce2bed4a6272/microsoft/TypeScript/issues/19546 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e0bb9f325571216dea8c40026b7dd843c420a9b4c7910dcd3eb0ce2bed4a6272/microsoft/TypeScript/issues/19546 |
| og:image:alt | TypeScript Version: 2.5.3 It could be I stumbled on something I simply don't understand, but it seems like this should work: Code enum Color { RED = "RED", BLUE = "BLUE", GREEN = "GREEN" } type Col... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aaronbeall |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| 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 | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| 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