Title: Wrong type inferred for indirect call of generic function · Issue #29638 · microsoft/TypeScript · GitHub
Open Graph Title: Wrong type inferred for indirect call of generic function · Issue #29638 · microsoft/TypeScript
X Title: Wrong type inferred for indirect call of generic function · Issue #29638 · microsoft/TypeScript
Description: TypeScript Version: 3.2.2 Search Terms: Generics, lookahead, type inference Code function call
Open Graph Description: TypeScript Version: 3.2.2 Search Terms: Generics, lookahead, type inference Code function call
X Description: TypeScript Version: 3.2.2 Search Terms: Generics, lookahead, type inference Code function call<P1, R>(f: (p1: P1) => R, p1: P1): R { return f(p1); } function identity<T>(o: T): T { r...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/29638
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wrong type inferred for indirect call of generic function ","articleBody":"**TypeScript Version:** 3.2.2\r\n\r\n**Search Terms:** Generics, lookahead, type inference\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction call\u003cP1, R\u003e(f: (p1: P1) =\u003e R, p1: P1): R {\r\n return f(p1);\r\n}\r\n\r\nfunction identity\u003cT\u003e(o: T): T {\r\n return o;\r\n}\r\n\r\nconst x = call(identity, 1);\r\n\r\n\r\n// When the parameters are reversed, it works:\r\n\r\nfunction callReversed\u003cP1, R\u003e(p1: P1, f: (p1: P1) =\u003e R): R {\r\n return f(p1);\r\n}\r\n\r\nconst y = callReversed(1, identity);\r\n```\r\n\r\n\r\n\r\n**Expected behavior:**\r\n\r\n`x` is of type `number`\r\n\r\n**Actual behavior:**\r\n\r\n`x` is of type `{}`\r\nonly `y` is of type number\r\n\r\n**Playground Link:** [Playground link](https://www.typescriptlang.org/play/#src=function%20call%3CP1%2C%20R%3E(f%3A%20(p1%3A%20P1)%20%3D%3E%20R%2C%20p1%3A%20P1)%3A%20R%20%7B%0A%20%20%20%20return%20f(p1)%3B%0A%7D%0A%0Afunction%20identity%3CT%3E(o%3A%20T)%3A%20T%20%7B%0A%20%20%20%20return%20o%3B%0A%7D%0A%0Aconst%20x%20%3D%20call(identity%2C%201)%3B%0A%0A%0A%2F%2F%20Reversed%3A%0A%0Afunction%20callReversed%3CP1%2C%20R%3E(p1%3A%20P1%2C%20f%3A%20(p1%3A%20P1)%20%3D%3E%20R)%3A%20R%20%7B%0A%20%20%20%20return%20f(p1)%3B%0A%7D%0A%0Aconst%20y%20%3D%20callReversed(1%2C%20identity)%3B%0A)\r\n\r\n**Related Issues:** I didn't find anything related, but maybe I have been using the wrong search term (\"lookahead\").\r\n","author":{"url":"https://github.com/tp","@type":"Person","name":"tp"},"datePublished":"2019-01-29T18:47:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/29638/TypeScript/issues/29638"}
| 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:3b281447-736e-b2b9-32dd-89d5f8f7f8bf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 819C:A1BA4:5C5088:7D3769:6A627D11 |
| html-safe-nonce | 7965a483a6ad606833e1f64481aac2d13f989c2ea4fb95b20c1f89085a3a3045 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTlDOkExQkE0OjVDNTA4ODo3RDM3Njk6NkE2MjdEMTEiLCJ2aXNpdG9yX2lkIjoiNTQ5NjA3MzA2MTIzMjk2NjkyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 27929b11ddafb04e19646d2da4b1dfefcac2a5a225f0104b73635a034753bec4 |
| hovercard-subject-tag | issue:404434172 |
| 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/29638/issue_layout |
| twitter:image | https://opengraph.githubassets.com/02ec490c80e650e2e1465f340a8a0d1f32b0ff7f42869ad671e0be848b4cd29a/microsoft/TypeScript/issues/29638 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/02ec490c80e650e2e1465f340a8a0d1f32b0ff7f42869ad671e0be848b4cd29a/microsoft/TypeScript/issues/29638 |
| og:image:alt | TypeScript Version: 3.2.2 Search Terms: Generics, lookahead, type inference Code function call |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tp |
| hostname | github.com |
| expected-hostname | github.com |
| None | 54d77223ecd96549586d00f1e91ee7d05feebf27ea430279a9c4ba4b7de1a93c |
| 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 | 4d79f1b99472a521fc5fb66e9fdc3ce742937dff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width