Title: NoInfer and overloaded function argument inference · Issue #57873 · microsoft/TypeScript · GitHub
Open Graph Title: NoInfer and overloaded function argument inference · Issue #57873 · microsoft/TypeScript
X Title: NoInfer and overloaded function argument inference · Issue #57873 · microsoft/TypeScript
Description: 🔎 Search Terms NoInfer, overload 🕗 Version & Regression Information Version 5.4.3 I was unable to test this on prior versions because this is a new feature ⏯ Playground Link https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOz...
Open Graph Description: 🔎 Search Terms NoInfer, overload 🕗 Version & Regression Information Version 5.4.3 I was unable to test this on prior versions because this is a new feature ⏯ Playground Link https://www.typescriptl...
X Description: 🔎 Search Terms NoInfer, overload 🕗 Version & Regression Information Version 5.4.3 I was unable to test this on prior versions because this is a new feature ⏯ Playground Link https://www.typescr...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57873
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NoInfer and overloaded function argument inference","articleBody":"### 🔎 Search Terms\r\n\r\nNoInfer, overload\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\nVersion 5.4.3\r\n- I was unable to test this on prior versions because this is a new feature\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwAcYdhkwQAKRALngDkcBJVREGAHgoEp4BeAPngA3HFmD8utbn0EixAbgBQoSLAQp02PIWKly7AIL8qtBs1YcKsAOa0DPAcNHjJ8KzFvx7MpwsWKwPABnDHgADykHWWc+HRIySmlHAEYuJUDUEPgATykbWhCYLFRrKN9gWKJ48goKITLUpSA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ndeclare function produce(f: NoInfer\u003c() =\u003e void\u003e): () =\u003e void;\r\ndeclare function produce\u003cA\u003e(f: NoInfer\u003c(arg: A) =\u003e void\u003e): (arg: A) =\u003e void;\r\n\r\nconst x: () =\u003e void = produce(() =\u003e 1); // works\r\nconst y: (arg: string) =\u003e void = produce((v) =\u003e 1); // Parameter 'v' implicitly has an 'any' type.\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nBecause `const y` is explicitly typed and thanks to the new utility `NoInfer` type, the compiler is able to figure out (from the return type) it is calling the `produce\u003cstring\u003e()` overload. (Without `NoInfer` it would just be `produce\u003cany\u003e()`). \r\n\r\nHowever, apparently it does not apply this knowledge to the function parameter `f` and thus the non type-hinted argument `v` is inferred as `any`\r\n\r\n\r\n\r\n### 🙂 Expected behavior\r\n\r\nSince the compiler already knows `f` is of type `NoInfer\u003c(arg:string)=\u003evoid\u003e` it should be able to infer the lambda argument `v` to be of `string` type.\r\n\r\n\r\n\r\n\r\n### Additional information about the issue\r\n\r\n_No response_","author":{"url":"https://github.com/kevinresol","@type":"Person","name":"kevinresol"},"datePublished":"2024-03-21T01:07:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/57873/TypeScript/issues/57873"}
| 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:363d4af3-0dda-8cb5-f876-7359a6a49aff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96BE:38E41B:B92C4D:FCF740:6A6199B1 |
| html-safe-nonce | 2faa9afaa5bff40bf27f7525e7291597754664fe366351fd645f592a9bdbeaad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkJFOjM4RTQxQjpCOTJDNEQ6RkNGNzQwOjZBNjE5OUIxIiwidmlzaXRvcl9pZCI6IjMzNjIyNDcwMjI2ODcxMzIwODEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 847a1b53ca70e4814773d0b301f43b33153f53facf9da26364ceec6d8523bc2a |
| hovercard-subject-tag | issue:2198884964 |
| 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/57873/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d77b9311c407ba55a8750053454d8873d4f652b6236ccead9c69237e18f1b1a/microsoft/TypeScript/issues/57873 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d77b9311c407ba55a8750053454d8873d4f652b6236ccead9c69237e18f1b1a/microsoft/TypeScript/issues/57873 |
| og:image:alt | 🔎 Search Terms NoInfer, overload 🕗 Version & Regression Information Version 5.4.3 I was unable to test this on prior versions because this is a new feature ⏯ Playground Link https://www.typescriptl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kevinresol |
| hostname | github.com |
| expected-hostname | github.com |
| None | c28c2f6607f2aacbd934868d997038895c9780d08babfe918550d73773326f4c |
| 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 | cd05235d52ffb3318513d883a56c87a121015c8b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width