Title: Higher order functions lose type parameters · Issue #417 · microsoft/TypeScript · GitHub
Open Graph Title: Higher order functions lose type parameters · Issue #417 · microsoft/TypeScript
X Title: Higher order functions lose type parameters · Issue #417 · microsoft/TypeScript
Description: When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how identityM has the generic type parameter A changed into {}, resulting in a loss of type safet...
Open Graph Description: When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how identityM has the generic type parameter A changed in...
X Description: When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how identityM has the generic type parameter A changed in...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/417
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Higher order functions lose type parameters","articleBody":"When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how `identityM` has the generic type parameter `A` changed into `{}`, resulting in a loss of type safety in the rest of the code.\n\nIdeally `identityM` would have the type `\u003cA\u003e(a: A) =\u003e A`. If this isn't possible, issuing a compiler warning (or error) about loss of genericity would be very helpful in tracking down errors like this.\n\n``` typescript\nfunction mirror\u003cA, B\u003e(f: (a: A) =\u003e B): (a: A) =\u003e B { return f; }\nfunction identity\u003cA\u003e(a: A): A { return a; }\nvar identityM = mirror(identity); // type: (a: {}) =\u003e {}\n\nvar x = 1;\nvar y = identity(x); // type: number\nvar z = identityM(x); // type: {}\n```\n","author":{"url":"https://github.com/wavebeem","@type":"Person","name":"wavebeem"},"datePublished":"2014-08-10T05:49:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/417/TypeScript/issues/417"}
| 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:4d9845d0-2338-4cfb-4c43-2e5a0db7723e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AAD2:E89C2:C76257:1145F1B:6A61A4F7 |
| html-safe-nonce | b8f215944ff0ef03be766447ca8f0acae752abceaa89245c0ac79c954c2f0239 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUQyOkU4OUMyOkM3NjI1NzoxMTQ1RjFCOjZBNjFBNEY3IiwidmlzaXRvcl9pZCI6IjQ5MDk5MTk4NjA1Mjc1NzIyMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 288305f1adbf1791df0c3a47d4926776a2b8362a1871650ab831247c2fc48269 |
| hovercard-subject-tag | issue:39901614 |
| 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/417/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8449ac5e11d4993452bf3eef2dda73c36df347f61fab06fd8002368781d89cf6/microsoft/TypeScript/issues/417 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8449ac5e11d4993452bf3eef2dda73c36df347f61fab06fd8002368781d89cf6/microsoft/TypeScript/issues/417 |
| og:image:alt | When making higher order functions that return functions, type parameters are not preserved in return type. Notice in the following example how identityM has the generic type parameter A changed in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wavebeem |
| 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