Title: Inferred type changes from 5.5 to 5.6 · Issue #60077 · microsoft/TypeScript · GitHub
Open Graph Title: Inferred type changes from 5.5 to 5.6 · Issue #60077 · microsoft/TypeScript
X Title: Inferred type changes from 5.5 to 5.6 · Issue #60077 · microsoft/TypeScript
Description: 🔎 Search Terms variance 🕗 Version & Regression Information This changed in commit or PR #57909 (bisected via every-ts) ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.2#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFzwB4AFAPgAoAoeHFfMgBx...
Open Graph Description: 🔎 Search Terms variance 🕗 Version & Regression Information This changed in commit or PR #57909 (bisected via every-ts) ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.2#code/CYUwxgNgh...
X Description: 🔎 Search Terms variance 🕗 Version & Regression Information This changed in commit or PR #57909 (bisected via every-ts) ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.2#code/CYUwx...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/60077
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inferred type changes from 5.5 to 5.6","articleBody":"### 🔎 Search Terms\n\n- variance\n\n### 🕗 Version \u0026 Regression Information\n\n- This changed in commit or PR #57909 (bisected via `every-ts`)\r\n\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?ts=5.6.2#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFzwB4AFAPgAoAoeHFfMgBxiXrXyIEp4BeE+ANyQBLYABoq8QSkEYA-GzGce8IgG4KFSRhAxsUMAiJMW8AN7i4AR3yYYkgOZrqzWdYy2UDigF91ydFkZmNG4cSmoGNiM0RV4AclixahN4S3wAIjT4LwU1CkCWADpnCgB6EvgAURgmGAkUeAAVAGV4AFYCgDYReBQkLEl4EFgIQW1+bTRBVDQKIA\n\n### 💻 Code\n\n```ts\r\ndeclare const f: \u003cP\u003e(\r\n fn: (props: P) =\u003e void,\r\n init?: P,\r\n) =\u003e P;\r\n\r\ninterface Props {\r\n req: string;\r\n opt?: string;\r\n}\r\n\r\nconst props = f(\r\n (p: Props) =\u003e '',\r\n { req: \"\" },\r\n);\r\n\r\nprops.opt\r\n// Error in TS 5.6, not in earlier versions\r\n```\r\n\n\n### 🙁 Actual behavior\n\n`P` is inferred as `{req: string}`, so accessing the optional property causes a TypeScript error.\n\n### 🙂 Expected behavior\n\n`P` should be inferred as `Props`, as it is in TS 5.5 (and earlier). If you drop the `init` parameter from the call to `f`, then `P` is also inferred to be `Props` in TS 5.6.\n\n### Additional information about the issue\n\nThis seems related to #59764 but I'm not sure it's the same, so I figured I'd file an issue. I tried the same code on the [playground] for #59709 and it does not fix this issue.\r\n\r\ncc @Andarist for whether TS 5.6 is right and I'm wrong 😄 \r\n\r\n[playground]: https://www.typescriptlang.org/play/?ts=5.7.0-pr-59709-8#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFzwB4AFAGngCUA+ACgCh4cV9qAHGJFtfIgSngF5KFEvXgBLFGIwB+biL6D4RANy1aEjCBjYoYBEXad4Ab1FwAjvkwwJAc1UMOMqxhsp7tAL5rk6LGw40ARw6BlZuQzQFIQByGJEGY3gLfAAiVPhPeVVaAM4AOidaIA","author":{"url":"https://github.com/danvk","@type":"Person","name":"danvk"},"datePublished":"2024-09-26T21:00:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/60077/TypeScript/issues/60077"}
| 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:5f2a41ee-56e7-3f75-31eb-8bb875095eb7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E27C:22B5CC:3CBFDB:4FBE51:6A614E66 |
| html-safe-nonce | bb583cc2f948cd177e457de79009bc502acb0a07b3b70bae05ef92b5c1ce31c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjdDOjIyQjVDQzozQ0JGREI6NEZCRTUxOjZBNjE0RTY2IiwidmlzaXRvcl9pZCI6Ijc0MTM5NzM0NzE1NTc5MzA1OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0d7b9c613d21d18089e77ea6d1a7b733bfe90f1d5d801edf1a53093ff666e6d5 |
| hovercard-subject-tag | issue:2551523755 |
| 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/60077/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f22419d8700d875a374176bc3746900f9c63da3077d510497a9487dba7d616d0/microsoft/TypeScript/issues/60077 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f22419d8700d875a374176bc3746900f9c63da3077d510497a9487dba7d616d0/microsoft/TypeScript/issues/60077 |
| og:image:alt | 🔎 Search Terms variance 🕗 Version & Regression Information This changed in commit or PR #57909 (bisected via every-ts) ⏯ Playground Link https://www.typescriptlang.org/play/?ts=5.6.2#code/CYUwxgNgh... |
| 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 | 35b919fdb8e6752d2ed95a144e761ca5e924557563e2ed0a5ebf6c4430cdeeb6 |
| 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 | 1e22b08b60ccb67c3791f565bed248565260e611 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width