Title: Unexpected type infer for function first argument with default value since 5.1 · Issue #57706 · microsoft/TypeScript · GitHub
Open Graph Title: Unexpected type infer for function first argument with default value since 5.1 · Issue #57706 · microsoft/TypeScript
X Title: Unexpected type infer for function first argument with default value since 5.1 · Issue #57706 · microsoft/TypeScript
Description: 🔎 Search Terms "type infer first argument" 🕗 Version & Regression Information This is a crash This changed between versions v5.0.4 and v5.1.6 This changed in commit or PR _______ This is the behavior in every version I tried, and I revie...
Open Graph Description: 🔎 Search Terms "type infer first argument" 🕗 Version & Regression Information This is a crash This changed between versions v5.0.4 and v5.1.6 This changed in commit or PR _______ This is the behavi...
X Description: 🔎 Search Terms "type infer first argument" 🕗 Version & Regression Information This is a crash This changed between versions v5.0.4 and v5.1.6 This changed in commit or PR _______ This...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57706
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected type infer for function first argument with default value since 5.1","articleBody":"### 🔎 Search Terms\r\n\r\n\"type infer first argument\"\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- [ ] This is a crash\r\n- [x] This changed between versions **v5.0.4** and **v5.1.6**\r\n- [ ] This changed in commit or PR _______\r\n- [ ] This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________\r\n- [ ] I was unable to test this on prior versions because _______\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play?ts=5.5.0-dev.20240308#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXy1URBgEYAeAFQD4AKRVALngDEpMcYBPK6gSmaUAUKEiwEKdNjwEiJAEy96TVuwycuimgPjChIAB4AHThngYuRhGw7de8ALzxasAOalBAGnhv5zKKhcfI7UPoH6xqbmltZqGlqhTrQAdKluAM7MANqU3gFcALrBDqH5QuVgeOlmiKSOzgC26a7M1TCErvUA5AAWIBAQOF3eGCDV-oHFoQDe8AC+QpWo1T51ToTEZPSkfEIA9HvwR-AAegD8i1VmUPL1GwrbuwfHpxeXyzW3SU0t8G0d3T6AyGU3gswWSxWACM7nItoh5E9Dsdzu9oWtZJt5PREftkUdUWizGBYZtSLRaD9Whh2qhOk5ev1Bl1QeCkS9UZDiV9MQ9Kc1qbT6fBGcCWSEwfN2Si3kA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nexport type Factory\u003cT> = (arg1: T, arg2: any) => any\r\nexport type Factory2\u003cT> = (...args: [T, any]) => any\r\n\r\ndeclare function infer1\u003cT>(fn: Factory\u003cT>): T\r\ndeclare function infer2\u003cT>(fn: Factory2\u003cT>): T\r\n\r\nconst f1 = (msg: string = 'hello', test: any) => { }\r\nconst a1 = infer1(f1)\r\n// ^? const a1: string | undefined\r\nconst a2 = infer2(f1)\r\n// ^? const a2: string | undefined\r\n\r\nconst f2 = (msg: string = 'hello') => { }\r\nconst b = infer1(f2)\r\n// ^? const b: string | undefined\r\nconst b1 = infer2(f2)\r\n// ^? const b1: string | undefined\r\n\r\nconst c = infer1((msg: string = 'hello') => { })\r\n// ^? const c: string\r\nconst c2 = infer2((msg: string = 'hello') => { })\r\n// ^? const c2: string | undefined\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nIn my code you'll notice that the type of `c` is not the same as `b`, but the argument we passing into function `infer1` is actually the same.\r\n\r\nI've tested this between v5.0.4 and v5.1.6, but the type of `c` is different:\r\n\r\n```ts\r\n// v5.0.4\r\nconst c: string | undefined\r\n\r\n// v5.1.6\r\nconst c: string\r\n```\r\n\r\nAfter checking v5.1 changelog, I'm still not sure what changes have been made between 5.0 to 5.1.\r\n\r\nSo I decided to submit this issue as a \"Bug report\".\r\n\r\n\r\n### 🙂 Expected behavior\r\n\r\nThe type of `c` is supposed to be `string | undefined`.\r\n\r\n### Additional information about the issue\r\n\r\n_No response_","author":{"url":"https://github.com/ShenQingchuan","@type":"Person","name":"ShenQingchuan"},"datePublished":"2024-03-09T03:04:06Z","url":"https://github.com/microsoft/TypeScript/issues/57706"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:53d5b9e2-06c9-2bb7-22a7-5ed5dc4a7e5d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C734:1AE20C:25AEA56:2FA9E4A:6B0187A0 |
| html-safe-nonce | 047ff6f1e1ed9844950f1355cbb02ac83de463a38543507fac65f7b9e0198cd1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzM0OjFBRTIwQzoyNUFFQTU2OjJGQTlFNEE6NkIwMTg3QTAiLCJ2aXNpdG9yX2lkIjoiNTUwNDA4NjQyMjI0NTcwNTYzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6c1762a6790914830920538477ab82931f24b065e866839340edb158eafd97e3 |
| hovercard-subject-tag | issue:2177024277 |
| 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/57706/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7421b3c7ae29f5eb312bcc50609cdc5ea3fc9be5715f4876f03b17e1c4cdf262/microsoft/TypeScript/issues/57706 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7421b3c7ae29f5eb312bcc50609cdc5ea3fc9be5715f4876f03b17e1c4cdf262/microsoft/TypeScript/issues/57706 |
| og:image:alt | 🔎 Search Terms "type infer first argument" 🕗 Version & Regression Information This is a crash This changed between versions v5.0.4 and v5.1.6 This changed in commit or PR _______ This is the behavi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ShenQingchuan |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width