Title: Using `ReturnType` with generic function parameters and generic property access · Issue #26856 · microsoft/TypeScript · GitHub
Open Graph Title: Using `ReturnType` with generic function parameters and generic property access · Issue #26856 · microsoft/TypeScript
X Title: Using `ReturnType` with generic function parameters and generic property access · Issue #26856 · microsoft/TypeScript
Description: TypeScript Version: 3.1.0-dev.20180901 Search Terms: ReturnType, generic, invoke, invoker, property Code function invoker Open Graph Description: TypeScript Version: 3.1.0-dev.20180901 Search Terms: ReturnType, generic, invoke, invoker, property Code function invoker X Description: TypeScript Version: 3.1.0-dev.20180901 Search Terms: ReturnType, generic, invoke, invoker, property Code function invoker <K extends string | number | symbol, A extends any[]> (key: K, ...arg...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26856
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using `ReturnType` with generic function parameters and generic property access","articleBody":"**TypeScript Version:** 3.1.0-dev.20180901\r\n\r\n**Search Terms:** `ReturnType`, `generic`, `invoke`, `invoker`, `property`\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction invoker \u003cK extends string | number | symbol, A extends any[]> (key: K, ...args: A) {\r\n return \u003cT extends Record\u003cK, (...args: A) => any>> (obj: T): ReturnType\u003cT[K]> => obj[key](...args)\r\n}\r\n\r\nconst result = invoker('test', true)({ test: (a: boolean) => 123 })\r\n```\r\n\r\nWorkaround (duplicate similar `ReturnType`-like type locally):\r\n\r\n```ts\r\nexport type InvokeResult \u003cT extends (...args: A) => any, A extends any[]> = T extends (...args: A) => infer R ? R : never\r\n\r\nexport function invoker \u003cK extends string | number | symbol, A extends any[]> (key: K, ...args: A) {\r\n return \u003cT extends Record\u003cK, (...args: A) => any>> (obj: T): InvokeResult\u003cT[K], A> => obj[key](...args)\r\n}\r\n```\r\n\r\n**Expected behavior:** Valid program and use of `ReturnType`.\r\n\r\n**Actual behavior:**\r\n\r\n```\r\nType '(...args: A) => any' does not satisfy the constraint '(...args: any[]) => any'.\r\n Types of parameters 'args' and 'args' are incompatible.\r\n Type 'any[]' is not assignable to type 'A'.\r\n```\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/index.html#src=function%20invoker%20%3CK%20extends%20string%20%7C%20number%20%7C%20symbol%2C%20A%20extends%20any%5B%5D%3E%20(key%3A%20K%2C%20...args%3A%20A)%20%7B%0D%0A%20%20return%20%3CT%20extends%20Record%3CK%2C%20(...args%3A%20A)%20%3D%3E%20any%3E%3E%20(obj%3A%20T)%3A%20ReturnType%3CT%5BK%5D%3E%20%3D%3E%20obj%5Bkey%5D(...args)%0D%0A%7D\r\n\r\n**Related Issues:** No, this is out of my skillset to debug tonight. Logging for posterity and help 😄 I did try different workarounds and found I couldn't workaround it with any usage of property access so I added that to the title. For instance, the exact same code inlined results in an empty interface:\r\n\r\n```ts\r\nexport function invoker \u003cK extends string | number | symbol, A extends any[]> (key: K, ...args: A) {\r\n return \u003cT extends Record\u003cK, (...args: A) => any>> (obj: T): T[K] extends (...args: A) => infer R ? R : never => obj[key](...args)\r\n}\r\n\r\nconst result = invoker('test', true)({ test: (abc: boolean) => 123 })\r\n```\r\n\r\nMore minimal repro which makes me realise it may not be an issue but maybe an enhance to `ReturnType` to specify the generic type parameters:\r\n\r\n```ts\r\ntype Test \u003cT extends (...args: A) => any, A extends any[]> = ReturnType\u003cT>\r\n```","author":{"url":"https://github.com/blakeembrey","@type":"Person","name":"blakeembrey"},"datePublished":"2018-09-03T04:57:18Z","url":"https://github.com/microsoft/TypeScript/issues/26856"}
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:908f7095-e991-72c3-77ff-6eb472719707 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id 85FE:6365:2B473D4:39C795B:6B01CB15 html-safe-nonce e60121a5ff4e2ff71b2dc1b7b530ae2afb872758e487906b39549c1d8aa12263 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUZFOjYzNjU6MkI0NzNENDozOUM3OTVCOjZCMDFDQjE1IiwidmlzaXRvcl9pZCI6IjQ3Mjc1NjIzNDM3ODgxNzAwMDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== visitor-hmac 8ed848c3bf8a93e1ae49d8a39be29a17cf089c1dd7eef7e6d51a0dbf4f8a6739 hovercard-subject-tag issue:356358162 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/26856/issue_layout twitter:image https://opengraph.githubassets.com/e6b72261518191f908f763ef23bf0827999d3ad0ede77ce0de6449d2a3cce6da/microsoft/TypeScript/issues/26856 twitter:card summary_large_image og:image https://opengraph.githubassets.com/e6b72261518191f908f763ef23bf0827999d3ad0ede77ce0de6449d2a3cce6da/microsoft/TypeScript/issues/26856 og:image:alt TypeScript Version: 3.1.0-dev.20180901 Search Terms: ReturnType, generic, invoke, invoker, property Code function invoker og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username blakeembrey 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
URLs of crawlers that visited me.