Title: Incorrent return type inference when using infer with generic function · Issue #48820 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrent return type inference when using infer with generic function · Issue #48820 · microsoft/TypeScript
X Title: Incorrent return type inference when using infer with generic function · Issue #48820 · microsoft/TypeScript
Description: Bug Report type ApplyFn
Open Graph Description: Bug Report type ApplyFn
X Description: Bug Report type ApplyFn<Fn extends (item: any) => any, T> = Fn extends (item: T) => infer R ? R : never type X = ApplyFn<(x: number) => string, number> type X is string type Fn...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48820
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrent return type inference when using infer with generic function","articleBody":"# Bug Report\r\n\r\n```typescript\r\ntype ApplyFn\u003cFn extends (item: any) =\u003e any, T\u003e =\r\n Fn extends (item: T) =\u003e infer R ? R : never\r\n\r\ntype X = ApplyFn\u003c(x: number) =\u003e string, number\u003e\r\n\r\n```\r\ntype X is `string`\r\n```typescript\r\ntype Fn = \u003cT\u003e(item: T) =\u003e {foo: T}\r\ntype Y = ApplyFn\u003cFn, string\u003e\r\n```\r\ntype Y is `{foo: unknown}` but I have expected `{foo: string}`\r\n\r\n### 🔎 Search Terms\r\n\r\ninfer generic function return type\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?#code/C4TwDgpgBAgmYBsQDEB2AeNUIA9gVQBMBnKACgEt8BbALigENUQBKKAXgD5HmAaKACrd2AWABQUKFlz4ipSjXoC2XKBVQAzCACcoAJSgB+fVHqoIANx3jxoSFAAaHWPCRp0ZHGYCu1AEY6KtzEwNrqAOb8qL4B2py24NBY7FDoQgoQdIJBUADeGgD2BUoAvgn2AJrOcIgoGGj8IWGo4fFiQA)\r\n\r\nIs there any workaround to solve this problem?\r\n","author":{"url":"https://github.com/user753","@type":"Person","name":"user753"},"datePublished":"2022-04-23T16:32:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/48820/TypeScript/issues/48820"}
| 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:2581b51f-7867-e3a6-e436-081ac8867eaf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 884C:83A89:4B4979:656BFB:6A629B33 |
| html-safe-nonce | e5c0475ac2d49edc4a61ebfca7daf97ef8f7f8c9e358e889dafa2e3724b5c523 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODRDOjgzQTg5OjRCNDk3OTo2NTZCRkI6NkE2MjlCMzMiLCJ2aXNpdG9yX2lkIjoiNjcyODU4MDE1MDkyMDkxMTY2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c5cbe5f8b676eb83a8d120f610ed5389d9451139b22a35a6ba0db4bb24d0cdab |
| hovercard-subject-tag | issue:1213356315 |
| 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/48820/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5bdf9f11f18a970eafb682aeddc9b51693dbd56338adbc77c5db76f71cc87b25/microsoft/TypeScript/issues/48820 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5bdf9f11f18a970eafb682aeddc9b51693dbd56338adbc77c5db76f71cc87b25/microsoft/TypeScript/issues/48820 |
| og:image:alt | Bug Report type ApplyFn |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | user753 |
| hostname | github.com |
| expected-hostname | github.com |
| None | a6443033349a18134b517627f043d4a59a5110337b879810c7229c2c7e28eda0 |
| 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 | d6c6cacbe32d3ddfd1796fbd1a39b8fb47b87daf |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width