Title: Function parameter type inference doesn't work with keyof of generic type · Issue #25759 · microsoft/TypeScript · GitHub
Open Graph Title: Function parameter type inference doesn't work with keyof of generic type · Issue #25759 · microsoft/TypeScript
X Title: Function parameter type inference doesn't work with keyof of generic type · Issue #25759 · microsoft/TypeScript
Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: function parameter type inference keyof generic Code function foo1
Open Graph Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: function parameter type inference keyof generic Code function foo1
X Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: function parameter type inference keyof generic Code function foo1<T>(foo: T, bar: {[key in keyof {foo: number}] : (x: T) => number }) ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/25759
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function parameter type inference doesn't work with keyof of generic type","articleBody":"**TypeScript Version:** 3.1.0-dev.201xxxxx\r\n\r\n**Search Terms:**\r\nfunction parameter type inference keyof generic\r\n**Code**\r\n\r\n```ts\r\nfunction foo1\u003cT>(foo: T, bar: {[key in keyof {foo: number}] : (x: T) => number }) {\r\n}\r\n\r\nfunction foo2\u003cT>(foo: T, bar: {[key in keyof T] : (x: T) => number }) {\r\n}\r\n\r\nfoo1({foo: 1}, {foo: x1 => x1.foo + 1})\r\nfoo2({foo: 1}, {foo: x2 => x2.foo + 1})\r\n\r\n```\r\n\r\n**Expected behavior:**\r\n`x2` has type `{foo:number}`\r\n**Actual behavior:**\r\nCompiler error \r\n`TS7006: Parameter 'x2' implicitly has an 'any' type.`\r\n\r\n`x1` has type `{foo:number}` \r\nbut\r\n`x2` has type `any`\r\n\r\n**Playground Link:** \r\n[Playground](http://www.typescriptlang.org/play/#src=function%20foo1%3CT%3E(foo%3A%20T%2C%20qwe%3A%20%7B%5Bkey%20in%20keyof%20%7Bfoo%3A%20number%7D%5D%20%3A%20(x%3A%20T)%20%3D%3E%20number%20%7D)%20%3A%20any%20%7B%0D%0A%20%20return%20%7B%7D%20as%20any%0D%0A%7D%0D%0A%0D%0Afunction%20foo2%3CT%3E(foo%3A%20T%2C%20qwe%3A%20%7B%5Bkey%20in%20keyof%20T%5D%20%3A%20(x%3A%20T)%20%3D%3E%20number%20%7D)%20%3A%20any%20%7B%0D%0A%20%20return%20%7B%7D%20as%20any%0D%0A%7D%0D%0A%0D%0Aconst%20f1%20%3D%20foo1(%7Bfoo%3A%201%7D%2C%20%7Bfoo%3A%20x%20%3D%3E%20x.foo%20%2B%201%7D)%0D%0Aconst%20f2%20%3D%20foo2(%7Bfoo%3A%201%7D%2C%20%7Bfoo%3A%20x%20%3D%3E%20x.foo%20%2B%201%7D)%0D%0A)\r\n","author":{"url":"https://github.com/user471","@type":"Person","name":"user471"},"datePublished":"2018-07-18T10:00:06Z","url":"https://github.com/microsoft/TypeScript/issues/25759"}
| 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:410c1e85-be29-0d6e-0b91-39b5902de43b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C626:EA09B:2531C96:3150006:6B019BD3 |
| html-safe-nonce | 99bd5502033bda8b4cf95cd0afccbc787caf031d1c5206aa8838425359333db3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjI2OkVBMDlCOjI1MzFDOTY6MzE1MDAwNjo2QjAxOUJEMyIsInZpc2l0b3JfaWQiOiI0OTY5OTQ4MDE1Njg0MDY2MjU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 19ab1755b6e9c37060b653b9fa84b050ee67501a66ba7ecfb8633fd46022ddd0 |
| hovercard-subject-tag | issue:342259847 |
| 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/25759/issue_layout |
| twitter:image | https://opengraph.githubassets.com/54fc6409122a065e6dec89d9e01c944108749c19207785e8fe40275bbf757ded/microsoft/TypeScript/issues/25759 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/54fc6409122a065e6dec89d9e01c944108749c19207785e8fe40275bbf757ded/microsoft/TypeScript/issues/25759 |
| og:image:alt | TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: function parameter type inference keyof generic Code function foo1 |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | user471 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width