Title: infer function generic signature from actual function's return type · Issue #49618 · microsoft/TypeScript · GitHub
Open Graph Title: infer function generic signature from actual function's return type · Issue #49618 · microsoft/TypeScript
X Title: infer function generic signature from actual function's return type · Issue #49618 · microsoft/TypeScript
Description: Suggestion function test
Open Graph Description: Suggestion function test
X Description: Suggestion function test<T>(fn: (prev: T) => T) { } test((prev) => ({ a: 1 })); // T is inferred as "unknown" 🔍 Search Terms Maybe an issue exists, but I wasn't sure what ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/49618
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"infer function generic signature from actual function's return type","articleBody":"# Suggestion\r\n\r\n\r\n```js\r\nfunction test\u003cT>(fn: (prev: T) => T) { }\r\ntest((prev) => ({ a: 1 })); // T is inferred as \"unknown\"\r\n```\r\n\r\n## 🔍 Search Terms\r\n\r\nMaybe an issue exists, but I wasn't sure what to search for. \"Infer generic function type from return value\" didn't really help.\r\n\r\n## ✅ Viability Checklist\r\n\r\n\u003c!--\r\n Suggestions that don't meet all these criteria are very, very unlikely to be accepted.\r\n We always recommend reviewing the TypeScript design goals before investing time writing\r\n a proposal for ideas outside the scope of the project.\r\n-->\r\nMy suggestion meets these guidelines:\r\n\r\n* [ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code. _not sure_\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n\r\n## ⭐ Suggestion\r\n\r\n`T` should be inferred as the type of the returned object, `{a: number}`\r\n\r\n## 📃 Motivating Example\r\n\r\nhttps://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABFApgZygHgCoD4AUwYAXIvgA4BOKAbqdgJSIC8uijiA3ogL4BQqDPgrUaTVmW4BDUgEZeDBgG4+QA\r\n\r\n## 💻 Use Cases\r\n\r\nmake life easier","author":{"url":"https://github.com/trusktr","@type":"Person","name":"trusktr"},"datePublished":"2022-06-21T02:49:50Z","url":"https://github.com/microsoft/TypeScript/issues/49618"}
| 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:a6450a19-358d-2741-86a5-e759883942c8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E54:19F84C:C799ED:1016595:6B00ED74 |
| html-safe-nonce | 64fdca3051e4404ae673b6f1e326d05da6a1963955ce05d516d430ab3525de8b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTU0OjE5Rjg0QzpDNzk5RUQ6MTAxNjU5NTo2QjAwRUQ3NCIsInZpc2l0b3JfaWQiOiIyODc3NjYyOTczODM5NjAxMDEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a93fce1562f54e3e83aefc9190cfa9845c1b0a315fd1f30eb80d26f324424640 |
| hovercard-subject-tag | issue:1277726034 |
| 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/49618/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ebd89870cae626331c5761b157a0c396de69565d796f7f7e34f64c8b590edef7/microsoft/TypeScript/issues/49618 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ebd89870cae626331c5761b157a0c396de69565d796f7f7e34f64c8b590edef7/microsoft/TypeScript/issues/49618 |
| og:image:alt | Suggestion function test |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trusktr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width