Title: Losing generics (composition/currying) · Issue #12838 · microsoft/TypeScript · GitHub
Open Graph Title: Losing generics (composition/currying) · Issue #12838 · microsoft/TypeScript
X Title: Losing generics (composition/currying) · Issue #12838 · microsoft/TypeScript
Description: I'm trying to work on TS typings for FP lib Ramda. Several users have reported issues that came down to similar inference issues triggered in the presence of composition/currying involving functions containing generics. Since FP encourag...
Open Graph Description: I'm trying to work on TS typings for FP lib Ramda. Several users have reported issues that came down to similar inference issues triggered in the presence of composition/currying involving function...
X Description: I'm trying to work on TS typings for FP lib Ramda. Several users have reported issues that came down to similar inference issues triggered in the presence of composition/currying involving func...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/12838
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Losing generics (composition/currying)","articleBody":"I'm trying to work on [TS typings](https://github.com/donnut/typescript-ramda/) for FP lib [Ramda](http://ramdajs.com/).\r\n[Several](https://github.com/donnut/typescript-ramda/issues/29) [users](https://github.com/donnut/typescript-ramda/issues/78) [have](https://github.com/donnut/typescript-ramda/issues/86) [reported](https://github.com/donnut/typescript-ramda/issues/92) [issues](https://github.com/donnut/typescript-ramda/issues/101) that came down to similar inference issues triggered in the presence of composition/currying involving functions containing generics.\r\nSince FP encourages composing point-free functions (the majority of which use generics for type inference), what breaks here aren't so much edge cases, but idiomatic usage.\r\n\r\n**TypeScript Version:** nightly (`2.2.0-dev.20161211`)\r\n\r\n**Code** (can paste into the [TS playground](https://www.typescriptlang.org/play/)):\r\n\r\n```ts\r\ndeclare function inc(n: number): number; // +1\r\ndeclare function identity\u003cT\u003e(a: T): T;\r\ndeclare function compose\u003cV0, T1\u003e(fn0: (x0: V0) =\u003e T1): (x0: V0) =\u003e T1;\r\ndeclare function compose\u003cV0, T1, T2\u003e(fn1: (x: T1) =\u003e T2, fn0: (x: V0) =\u003e T1): (x: V0) =\u003e T2;\r\ndeclare function pipe \u003cV0, T1\u003e(fn0: (x0: V0) =\u003e T1): (x0: V0) =\u003e T1; // arity 1: same as compose\r\ndeclare function pipe \u003cV0, T1, T2\u003e(fn0: (x: V0) =\u003e T1, fn1: (x: T1) =\u003e T2): (x: V0) =\u003e T2; // arity 2: params swapped\r\n\r\n// don't use generics if it can't resolve them right away:\r\ncompose(identity) // generics lost, now {} =\u003e {}\r\npipe (identity) // ditto\r\n// argument order apparently matters too:\r\npipe (inc, identity); // ok, number -\u003e number\r\ncompose(identity, inc); // nope, number =\u003e {}\r\n// also no reasoning backward:\r\ncompose(inc, identity); // {} =\u003e number\r\npipe (identity, inc); // {} =\u003e number\r\n```\r\n\r\n**Expected behavior:**\r\n- `identity` survives composition\r\n- `identity` not killing the type signature when composing with `inc`\r\n\r\n**Actual behavior:**\r\n- Things break as soon as TS gets a generic it can't immediately resolve (as opposed to keeping them intact).\r\n- Even the same thing using different param order breaks for some reason.\r\n","author":{"url":"https://github.com/KiaraGrouwstra","@type":"Person","name":"KiaraGrouwstra"},"datePublished":"2016-12-11T16:37:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/12838/TypeScript/issues/12838"}
| 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:0299c12f-b95b-adf8-7ffc-57e2becbcafd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C70C:F8EC2:CD608F:1221049:6A61C9B6 |
| html-safe-nonce | 8b23477c8163f4489954b2ed11630713b2d1355603225a7cbf8038bc9f1498c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzBDOkY4RUMyOkNENjA4RjoxMjIxMDQ5OjZBNjFDOUI2IiwidmlzaXRvcl9pZCI6IjQyNzkzNzUxMTA1MDY0MDAxODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f63c52be55c15f574d7c8646287b05230d656bb0220a54ce1237ff5639d012db |
| hovercard-subject-tag | issue:194841289 |
| 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/12838/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74868d3b9cb46ab09ab479e61484a0d2693aa984e2db67ced1b3152e3df242e8/microsoft/TypeScript/issues/12838 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74868d3b9cb46ab09ab479e61484a0d2693aa984e2db67ced1b3152e3df242e8/microsoft/TypeScript/issues/12838 |
| og:image:alt | I'm trying to work on TS typings for FP lib Ramda. Several users have reported issues that came down to similar inference issues triggered in the presence of composition/currying involving function... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KiaraGrouwstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | b2de8c74e5e61e893155ba46ee41bc66170c1644cb795adefa8386d490f7781c |
| 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 | d1866027ded575df8a15c731dd8b9986c9483ceb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width