Title: Mapped tuples types iterates over all properties · Issue #27995 · microsoft/TypeScript · GitHub
Open Graph Title: Mapped tuples types iterates over all properties · Issue #27995 · microsoft/TypeScript
X Title: Mapped tuples types iterates over all properties · Issue #27995 · microsoft/TypeScript
Description: TypeScript Version: 3.2.0-dev.20181019 Search Terms: mapped tuples reify Code type Foo = ['a', 'b']; interface Bar { a: string; b: number; } type Baz = { [K in keyof Foo]: Bar[Foo[K]]; }; // Expected Baz to be [string, number] Expected b...
Open Graph Description: TypeScript Version: 3.2.0-dev.20181019 Search Terms: mapped tuples reify Code type Foo = ['a', 'b']; interface Bar { a: string; b: number; } type Baz = { [K in keyof Foo]: Bar[Foo[K]]; }; // Expect...
X Description: TypeScript Version: 3.2.0-dev.20181019 Search Terms: mapped tuples reify Code type Foo = ['a', 'b']; interface Bar { a: string; b: number; } type Baz = { [K in keyof Foo]: Bar[Foo[K...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27995
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mapped tuples types iterates over all properties","articleBody":"**TypeScript Version:** 3.2.0-dev.20181019\r\n\r\n**Search Terms:** mapped tuples reify\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Foo = ['a', 'b'];\r\ninterface Bar\r\n{\r\n\ta: string;\r\n\tb: number;\r\n}\r\n\r\ntype Baz = { [K in keyof Foo]: Bar[Foo[K]]; }; // Expected Baz to be [string, number]\r\n```\r\n\r\n**Expected behavior:** Baz should be [string, number]\r\n\r\n**Actual behavior:** Type '[\"a\", \"b\"][K]' cannot be used to index type 'Bar'.\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/index.html#src=type%20Foo%20%3D%20%5B'a'%2C%20'b'%5D%3B%0D%0Ainterface%20Bar%0D%0A%7B%0D%0A%09a%3A%20string%3B%0D%0A%09b%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Atype%20Baz%20%3D%20%7B%20%5BK%20in%20keyof%20Foo%5D%3A%20Bar%5BFoo%5BK%5D%5D%3B%20%7D%3B%20%2F%2F%20Expected%20Baz%20to%20be%20%5Bstring%2C%20number%5D%0D%0A%0D%0Atype%20WorkingBaz%20%3D%20%7B%20%5BK%20in%20Exclude%3Ckeyof%20Foo%2C%20keyof%20any%5B%5D%3E%5D%3A%20Foo%5BK%5D%20extends%20keyof%20Bar%20%3F%20Bar%5BFoo%5BK%5D%5D%20%3A%20never%3B%20%7D%20%26%20%7B%20length%3A%20Foo%5B'length'%5D%3B%20%7D%20%26%20any%5B%5D%3B\r\n\r\n**Related Issues:** https://github.com/Microsoft/TypeScript/issues/25947\r\n\r\n\r\nGiven the Mapped tuple types feature (#25947). I'd expect the code above to work cleanly.\r\n\r\nHowever, I still need to do:\r\n```ts\r\ntype WorkingBaz = { [K in Exclude\u003ckeyof Foo, keyof any[]\u003e]: Foo[K] extends keyof Bar ? Bar[Foo[K]] : never; } \u0026 { length: Foo['length']; } \u0026 any[];\r\n```\r\n\r\nTo have an equivalent type. As far as I understand, the \"K\" in a mapped type on a tuple should iterate only on numeric keys of this tuple. Therefore, Foo[K] should always be a valid key for Bar...","author":{"url":"https://github.com/lemoinem","@type":"Person","name":"lemoinem"},"datePublished":"2018-10-19T19:16:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":37},"url":"https://github.com/27995/TypeScript/issues/27995"}
| 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:9d700728-0fbb-4756-9553-8f37f93214b1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9AE0:80108:5310C7:78D660:6A61EBCA |
| html-safe-nonce | 5d035a42fa4bb22318a1a89a57ce0fd96913106c59e9717b55d50b84562a5476 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUUwOjgwMTA4OjUzMTBDNzo3OEQ2NjA6NkE2MUVCQ0EiLCJ2aXNpdG9yX2lkIjoiODY3MjYwOTA4NDk4NTQzNzEzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | de00755ff5eab1c353902093ca6c8ee8250d7e31ce28e24a63cb3e159fe149ea |
| hovercard-subject-tag | issue:372083342 |
| 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/27995/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6ce7c05136064bfef9b7613a1eb6aa195da4146b3459600538213c6fae7b170d/microsoft/TypeScript/issues/27995 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6ce7c05136064bfef9b7613a1eb6aa195da4146b3459600538213c6fae7b170d/microsoft/TypeScript/issues/27995 |
| og:image:alt | TypeScript Version: 3.2.0-dev.20181019 Search Terms: mapped tuples reify Code type Foo = ['a', 'b']; interface Bar { a: string; b: number; } type Baz = { [K in keyof Foo]: Bar[Foo[K]]; }; // Expect... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lemoinem |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5dd1217fff37e297563b9d318ee02bf6378c8957c6195b77786bb8896fc9c95d |
| 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 | 554667f6dda2a53c83687de64fabc457970f0f04 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width