Title: TypeScript can't infer type of default parameters · Issue #59643 · microsoft/TypeScript · GitHub
Open Graph Title: TypeScript can't infer type of default parameters · Issue #59643 · microsoft/TypeScript
X Title: TypeScript can't infer type of default parameters · Issue #59643 · microsoft/TypeScript
Description: 🔎 Search Terms infer default parameters function wrapper function factory 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ I tried down to version 4.0.3 (since in the earlier versio...
Open Graph Description: 🔎 Search Terms infer default parameters function wrapper function factory 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ I tried down to ve...
X Description: 🔎 Search Terms infer default parameters function wrapper function factory 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ I tried down t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59643
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeScript can't infer type of default parameters","articleBody":"### 🔎 Search Terms\r\n\r\ninfer default parameters\r\nfunction wrapper\r\nfunction factory\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ\r\n - I tried down to version 4.0.3 (since in the earlier version `Generator` type is not generic)\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVNQBEQYsA3EAHgEF4QAPDEVYAZ3jQGtUcB3VANoBdADTwASgD4AFACh4CggC540gHQbYAc1YrqASngBeSfADizElAw4YlLj35ipI2fpUO++APQAqX-AAtjhgnCDA8HAYyDD4vt4A3LKyiEQk5CDSKOjYePC+0lDG8AAMYgBGxQDkVYYA3vLwYHisOBAgahA4WtINivBQrvDe3vAAegD8jQrl8iPjUwoAvvpJK0lAA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ndeclare function fnDerive\u003cA extends unknown[], R>(\r\n fn: (...args: A) => Generator\u003cunknown, R>,\r\n): unknown /** mocked return */;\r\n\r\nfnDerive(function *(a = 0, b = '') {\r\n console.log({\r\n a,\r\n // ^?\r\n b\r\n // ^?\r\n });\r\n});\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe type of `a` and `b` is `unknown`.\r\n\r\n\u003cimg width=\"480\" alt=\"image\" src=\"https://github.com/user-attachments/assets/a509fbe0-65c9-4e3d-855d-3a5cdd9729c0\">\r\n\r\n### 🙂 Expected behavior\r\n\r\nThe type of `a` and `b` should be `number` and `string`\r\n\r\n### Additional information about the issue\r\n\r\nI was working with a library [`gensync`](https://www.npmjs.com/package/gensync) when I hit this issue, and I extracted the minimum reproduction out of it.\r\n\r\nNote that if I don't use default parameters, typescript can infer the `a` and `b` types correctly:\r\n\r\n```ts\r\ndeclare function fnDerive\u003cA extends unknown[], R>(\r\n fn: (...args: A) => Generator\u003cunknown, R>,\r\n): unknown /** mocked return */;\r\n\r\nfnDerive(function *(a?: number | undefined, b?: string | undefined) {\r\n console.log({\r\n a,\r\n // ^?\r\n b\r\n // ^?\r\n });\r\n\r\n a ??= 0;\r\n b ??= '';\r\n console.log({\r\n a,\r\n // ^?\r\n b\r\n // ^?\r\n });\r\n});\r\n\r\n```\r\n\r\n\u003cimg width=\"653\" alt=\"image\" src=\"https://github.com/user-attachments/assets/be8b0785-0e9b-44b5-8559-40a03c670368\">\r\n","author":{"url":"https://github.com/SukkaW","@type":"Person","name":"SukkaW"},"datePublished":"2024-08-15T14:52:22Z","url":"https://github.com/microsoft/TypeScript/issues/59643"}
| 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:1c325925-540e-4d1f-9b8c-5b810e66d5ec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C22:1087D4:234DDFC:2F2CBA5:6B0199E4 |
| html-safe-nonce | 3e27ca968fbaba4c009730b46af560e57a03833f16be3e7e8b76311486af85aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzIyOjEwODdENDoyMzREREZDOjJGMkNCQTU6NkIwMTk5RTQiLCJ2aXNpdG9yX2lkIjoiNTE0MzYxNDMyNTc4NTYyNTMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5208f9245cb0ea1e1d43a460557768e1ee9288a258dabdcbd1649ac514a5d0a8 |
| hovercard-subject-tag | issue:2468227861 |
| 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/59643/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d96b8e2e0c70b6ae9437428cc5145d17630eaa8afae676989fa24df5ba14927a/microsoft/TypeScript/issues/59643 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d96b8e2e0c70b6ae9437428cc5145d17630eaa8afae676989fa24df5ba14927a/microsoft/TypeScript/issues/59643 |
| og:image:alt | 🔎 Search Terms infer default parameters function wrapper function factory 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ I tried down to ve... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SukkaW |
| 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