Title: Unable to read properties off object spread in generic function parameter (regression with 4.6.1-rc) · Issue #47865 · microsoft/TypeScript · GitHub
Open Graph Title: Unable to read properties off object spread in generic function parameter (regression with 4.6.1-rc) · Issue #47865 · microsoft/TypeScript
X Title: Unable to read properties off object spread in generic function parameter (regression with 4.6.1-rc) · Issue #47865 · microsoft/TypeScript
Description: Bug Report I noticed a regression between TypeScript 4.6.0-beta and 4.6.1-rc in my repo where parameters to generic functions that use object spread sometimes get an unusable type. 🔎 Search Terms object spread 4.6.1-rc 🕗 Version & Regres...
Open Graph Description: Bug Report I noticed a regression between TypeScript 4.6.0-beta and 4.6.1-rc in my repo where parameters to generic functions that use object spread sometimes get an unusable type. 🔎 Search Terms o...
X Description: Bug Report I noticed a regression between TypeScript 4.6.0-beta and 4.6.1-rc in my repo where parameters to generic functions that use object spread sometimes get an unusable type. 🔎 Search Terms o...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47865
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable to read properties off object spread in generic function parameter (regression with 4.6.1-rc)","articleBody":"# Bug Report\r\n\r\nI noticed a regression between TypeScript 4.6.0-beta and 4.6.1-rc in my repo where parameters to generic functions that use object spread sometimes get an unusable type.\r\n\r\n### 🔎 Search Terms\r\n\r\n- object spread\r\n- 4.6.1-rc\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.6.0-beta and 4.6.1-rc.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?#code/PQKhAIFEA8BcCcCGBjW4AOikFsDO4AzeAe23EQDtwBTadea3fTWAC3AApqA6Ac2-AByYLlgBXACbUKsXMABcoydNgBJCYICUAkMACwAKFrpi8NLACe6alDhJUAJWJjY1AApZEeADwAVGnDSEvii8ACWFLwAfOAAvOChEbwBrhTB4L6G4OAA-OAO1MimEt6JkQA0CQhJUVng8hkpQfgABgAkAN4RBNTw4AD6AMqwWLAAvvKd3b3gHjhjwFMUPX0FomMtdXkdANoA1uARs55kAD7ge9QWxAS2CCiwTi7uJ7jea7BRALoNZbxjdQa-loqXS7S6yxmQxGZgmSxWx3mmwM2W2+0OVDmXh+VXCkQBKPq4A6YwA3IZDFJkAAbLA2AhiCioMLEKi8aiwPxNNIhaqRKIcOosVhA8p1ViUCTU3oNDiYHC4Bowe6OZyuLE+XxRTRxGIAN2IYQkYoMmgaBqN5IMhnZsA4wmFCgIxGIwFgrvkACMsIJKhwOs7iJVuCHcNSxLxcGMdbEYh06kUKKJid74GM4glw5HSdlgMBwMQDkdfINwAAWbgANm4AAYALSejmIcCelzgCjENDF0sV6sARjr8GQCdZuGI0u41OIvH9qejVvnFIMtvtwEd8kDbo9qd9mYj+FjxJHSbQHTnGbD+5z4DzBaLVE9ndYx7HE6nM7PWEXBm-QA)\r\n\r\n### 💻 Code\r\n\r\n(see comment below for a simpler repro: https://github.com/microsoft/TypeScript/issues/47865#issuecomment-1039290983)\r\n\r\n```ts\r\n/** Extract params from an express path (e.g. '/students/:studentId'). */\r\nexport type ExtractRouteParams\u003cT extends string> = string extends T\r\n ? Record\u003cstring, string>\r\n : T extends `${infer _Start}:${infer Param}/${infer Rest}`\r\n ? {[k in Param | keyof ExtractRouteParams\u003cRest>]: string}\r\n : T extends `${infer _Start}:${infer Param}`\r\n ? {[k in Param]: string}\r\n : {};\r\n\r\ndeclare function get\u003cT extends string>(\r\n path: T,\r\n handler: (params: ExtractRouteParams\u003cT>) => void,\r\n): void;\r\n\r\nget('/path/:foo/to/:bar', ({foo, ...slugs}) => {\r\n const {bar} = slugs; // ok in TS 4.6.0-beta but not in TS 4.6.1-rc\r\n console.log({bar});\r\n});\r\n\r\nget('/path/:foo/to/:bar', slugs => {\r\n const {bar} = slugs; // ok in both\r\n console.log({bar});\r\n});\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nUsing object spread in a function parameter produces an unusable type in TS 4.6.1-rc.\r\n\r\nThe type of `slugs` in the first example is:\r\n\r\n slugs: { bar: string; }\r\n\r\nin TypeScript 4.6.0-beta but:\r\n\r\n slugs: Omit\u003cExtractRouteParams\u003cT>, \"foo\">\r\n\r\nin TypeScript 4.6.1-rc.\r\n\r\nThese are both the same (assuming `T = \"/path/:foo/to/:bar\"`) but the latter doesn't let me read any properties off of it.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI should be able to read `bar` off of `slugs`.\r\n\r\n\u003c!-- What you expected to happen instead, and why -->\r\n","author":{"url":"https://github.com/danvk","@type":"Person","name":"danvk"},"datePublished":"2022-02-12T16:58:07Z","url":"https://github.com/microsoft/TypeScript/issues/47865"}
| 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:e62aafd5-b3ff-b815-87da-da8770cc08c6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E06E:96DDF:1E33ECC:263A5FF:6B015BE4 |
| html-safe-nonce | a3916ea413d7d7b0063ad28949daf02245298977c50e16a7e306edb73b5002ce |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDZFOjk2RERGOjFFMzNFQ0M6MjYzQTVGRjo2QjAxNUJFNCIsInZpc2l0b3JfaWQiOiI0Mjg4Mjc3MDIyOTQzMzA0Njc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c1ae3762f9a038b1650d13e89de0df6815624503e1e79b9d2fd24ec9a385244a |
| hovercard-subject-tag | issue:1134292658 |
| 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/47865/issue_layout |
| twitter:image | https://opengraph.githubassets.com/69fa8d08e316e8697029a8b1c11830281044dd9e9ae09b6c267b9de6340cd963/microsoft/TypeScript/issues/47865 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/69fa8d08e316e8697029a8b1c11830281044dd9e9ae09b6c267b9de6340cd963/microsoft/TypeScript/issues/47865 |
| og:image:alt | Bug Report I noticed a regression between TypeScript 4.6.0-beta and 4.6.1-rc in my repo where parameters to generic functions that use object spread sometimes get an unusable type. 🔎 Search Terms o... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danvk |
| 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