Title: Return type of partially applied bound generic function · Issue #47899 · microsoft/TypeScript · GitHub
Open Graph Title: Return type of partially applied bound generic function · Issue #47899 · microsoft/TypeScript
X Title: Return type of partially applied bound generic function · Issue #47899 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms partial application generic bind return type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about bind, generics, partial application ⏯ Playg...
Open Graph Description: Bug Report 🔎 Search Terms partial application generic bind return type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about bin...
X Description: Bug Report 🔎 Search Terms partial application generic bind return type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47899
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Return type of partially applied bound generic function","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\npartial application generic bind return type\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about bind, generics, partial application\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.6.0-dev.20220211#code/GYVwdgxgLglg9mABAQwDwBVEFMAeUtgAmAzogIIBOFyAnqsmDQHxMAUDl1NAXIugJS9MAbwBQiCYgpYoICkg5VaAblEBfUaIA2MxACNEAXhQA6PTCKtwhLMAtZCAGkQBtAIwBdfssQB6X-qIABbIpFA0AA5YiKz8RkwojC4e2roQRjFxhgnIrO5ePpJFkv6I6SFhkdGx8YhgIAC2elgUyZqipQBiclBBLYjEMA0RWjB2DpqgkLAIiDA2YLDhGFVsyBQA5kJVgnxViGIS0rLyKJuqGqlQiIQZ8wRLNGYWhFZEtvZOiABE+MRQ328fgCtwqiHCUUytXAAGswHAAO5gK7YDI1bJzBaPVi-LD-QGFYpFUrRMEQ6pZBL-CgWDZAA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nfunction a\u003cT extends Array\u003cany\u003e\u003e(anArray: T): T {\r\n return anArray;\r\n}\r\n\r\nlet b = a.bind(undefined, [1]); // b has type () =\u003e any[]\r\nlet c = () =\u003e a([1]); // c has type () =\u003e number[]\r\n\r\n\r\n// Further simplified\r\n\r\nfunction identity\u003cType\u003e(arg: Type): Type {\r\n return arg;\r\n}\r\n\r\nlet d = identity.bind(undefined, \"test\"); // d has type () =\u003e unknown\r\nlet e = () =\u003e identity(\"test\"); // e has type () =\u003e string\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe types of b and c are different, and the types of d and e are different.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI'd expect them to both have the same type (b that of c, ```() =\u003e number[])```, d that of e ```() =\u003e string```), as the expressions are doing the same thing (arrow function vs bind for partial application of a function).\r\n\r\nThis limitation is noted in a [comment](https://github.com/microsoft/TypeScript/pull/27028#issuecomment-429334450) to the \"Strict bind, call, and apply methods on functions\" PR, but I couldn't find an actual issue referencing this behaviour.\r\nThat comment is also mentioned as a known limitation in a [similar issue](https://github.com/microsoft/TypeScript/issues/28900#issuecomment-445305567) which was closed in #28920, but unfortunately that pr only fixes the issue when binding only this, and not other parameters.\r\n","author":{"url":"https://github.com/thscott","@type":"Person","name":"thscott"},"datePublished":"2022-02-14T23:34:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/47899/TypeScript/issues/47899"}
| 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:1af9001e-509b-296f-7dac-86eb7d692240 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C86:3332B6:131249C:1A5F2B4:6A61B54A |
| html-safe-nonce | eb174008e50453209466de967d4b02736d0706eea9b4c00bc6721f508bcfb588 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Qzg2OjMzMzJCNjoxMzEyNDlDOjFBNUYyQjQ6NkE2MUI1NEEiLCJ2aXNpdG9yX2lkIjoiMjgzMjA5MjQ5NDY0NTI3ODAyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e58891aada85f3bd5cf62951ea2392edba9141b091a8762cea1506f9049f9909 |
| hovercard-subject-tag | issue:1137975883 |
| 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/47899/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ec501af89c2396529b40a77d11ddb4cded366a838b908264167b9d555187f1f1/microsoft/TypeScript/issues/47899 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ec501af89c2396529b40a77d11ddb4cded366a838b908264167b9d555187f1f1/microsoft/TypeScript/issues/47899 |
| og:image:alt | Bug Report 🔎 Search Terms partial application generic bind return type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about bin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thscott |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f4633bcf01c1ad14b73fd07dd39ac31d61f3d3c2578ee08ec1792b7b351eeb9 |
| 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 | ac296ae7f21856f1f92adbad22f870b6fbb4b907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width