Title: keyof {[n: number]: any} should be string, not never · Issue #22105 · microsoft/TypeScript · GitHub
Open Graph Title: keyof {[n: number]: any} should be string, not never · Issue #22105 · microsoft/TypeScript
X Title: keyof {[n: number]: any} should be string, not never · Issue #22105 · microsoft/TypeScript
Description: TypeScript Version: 2.8.0-dev.20180216 Search Terms: keyof numeric indexer Code // Behaviour with string keys type StringKeys1 = {a: any, b: any, c: any}; // Specific keys only type StringKeys2 = {[s: string]: any}; // Indexer only type ...
Open Graph Description: TypeScript Version: 2.8.0-dev.20180216 Search Terms: keyof numeric indexer Code // Behaviour with string keys type StringKeys1 = {a: any, b: any, c: any}; // Specific keys only type StringKeys2 = {...
X Description: TypeScript Version: 2.8.0-dev.20180216 Search Terms: keyof numeric indexer Code // Behaviour with string keys type StringKeys1 = {a: any, b: any, c: any}; // Specific keys only type StringKeys2 = {...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22105
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"keyof {[n: number]: any} should be string, not never","articleBody":"**TypeScript Version:** 2.8.0-dev.20180216\r\n\r\n**Search Terms:** \r\n- keyof\r\n- numeric indexer\r\n\r\n**Code**\r\n\r\n```ts\r\n// Behaviour with string keys\r\ntype StringKeys1 = {a: any, b: any, c: any}; // Specific keys only\r\ntype StringKeys2 = {[s: string]: any}; // Indexer only\r\ntype StringKeys3 = {[s: string]: any, foo: any}; // Indexer + some keys\r\ntype S1 = keyof StringKeys1; // S1 = \"a\" | \"b\" | \"c\"\r\ntype S2 = keyof StringKeys2; // S2 = string\r\ntype S3 = keyof StringKeys3; // S3 = string\r\n\r\n// Behaviour with numeric keys\r\ntype NumberKeys1 = {1: any, 2: any, 3: any}; // Specific keys only\r\ntype NumberKeys2 = {[n: number]: any}; // Indexer only\r\ntype NumberKeys3 = {[n: number]: any, 42: any}; // Indexer + some keys\r\ntype N1 = keyof NumberKeys1; // N1 = \"1\" | \"2\" | \"3\"\r\ntype N2 = keyof NumberKeys2; // N2 = never \u003c===== should be string\r\ntype N3 = keyof NumberKeys3; // N3 = \"42\" \u003c===== should be string\r\n```\r\n\r\n**Expected behavior:**\r\n`N2` and `N3` should be `string`.\r\n\r\n**Actual behavior:**\r\n`N2` is `never` and `N3` is `\"42\"`.\r\n\r\n\r\n**Related Issues:**\r\n#13715 seems related but isn't really - it is asking for `keyof T` to allow numbers.\r\n\r\n#22042 has [an example](https://github.com/Microsoft/TypeScript/issues/22042#issuecomment-367069253) showing how `lodash` typings incorrectly produce `never` for objects that have numeric indexers.\r\n\r\n**Discussion:**\r\nIn JavaScript, both string and numeric keys end up effectively being string keys. `keyof` uniformly handles string keys, numeric keys, and string indexers. Why does it ignore numeric indexers?\r\n","author":{"url":"https://github.com/yortus","@type":"Person","name":"yortus"},"datePublished":"2018-02-22T02:00:22Z","url":"https://github.com/microsoft/TypeScript/issues/22105"}
| 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:65e5d9d0-753f-849b-160c-2f148dcd0ac9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA56:20AA01:FD3215:14445EC:6B00FF11 |
| html-safe-nonce | 57e507b456cce01a69c2e57159ec9f98d7b768543c2b3931942d97f233fe333a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTU2OjIwQUEwMTpGRDMyMTU6MTQ0NDVFQzo2QjAwRkYxMSIsInZpc2l0b3JfaWQiOiI0MDQ0NTA0MTQxMDM1Mjc0MDAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b5674af93d9b77afd604bf75406c2c664e79b8225bcd286a37d3100febed0ee1 |
| hovercard-subject-tag | issue:299196376 |
| 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/22105/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dfa455aa4ea7ede108c9bdc0cfc7d2c0475da19dc0e40e472313e11831b4d5f2/microsoft/TypeScript/issues/22105 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dfa455aa4ea7ede108c9bdc0cfc7d2c0475da19dc0e40e472313e11831b4d5f2/microsoft/TypeScript/issues/22105 |
| og:image:alt | TypeScript Version: 2.8.0-dev.20180216 Search Terms: keyof numeric indexer Code // Behaviour with string keys type StringKeys1 = {a: any, b: any, c: any}; // Specific keys only type StringKeys2 = {... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yortus |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width