Title: Assignability false positive for recursive mapped types, even when fully instantiated · Issue #55535 · microsoft/TypeScript · GitHub
Open Graph Title: Assignability false positive for recursive mapped types, even when fully instantiated · Issue #55535 · microsoft/TypeScript
X Title: Assignability false positive for recursive mapped types, even when fully instantiated · Issue #55535 · microsoft/TypeScript
Description: 🔎 Search Terms recursive mapped types, assignability, depth check, deeply nested 🕗 Version & Regression Information If this is in fact a bug, it looks like it was introduced in v4.5 This can cause a runtime error when using incompatible ...
Open Graph Description: 🔎 Search Terms recursive mapped types, assignability, depth check, deeply nested 🕗 Version & Regression Information If this is in fact a bug, it looks like it was introduced in v4.5 This can cause ...
X Description: 🔎 Search Terms recursive mapped types, assignability, depth check, deeply nested 🕗 Version & Regression Information If this is in fact a bug, it looks like it was introduced in v4.5 This can ca...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/55535
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Assignability false positive for recursive mapped types, even when fully instantiated","articleBody":"### 🔎 Search Terms\r\n\r\nrecursive mapped types, assignability, depth check, deeply nested\r\n\r\n### 🕗 Version & Regression Information\r\nIf this is in fact a bug, it looks like it was introduced in v4.5\r\n\r\n- This can cause a runtime error when using incompatible values whose types are derived from recursive mapped types with more than 2 levels of nesting because the compiler seems to consider them equal (even when the derived type is fully instantiated (not infinite)).\r\n- This changed between versions v4.4 and v4.5\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://tsplay.dev/WoM1gN\r\n\r\n### 💻 Code\r\n\r\n```typescript\r\ntype Id\u003cT> = { [K in keyof T]: Id\u003cT[K]> }\r\n\r\ntype HasNumeric = Id\u003c{ x: { y: { z: number } } }>\r\n// ^? type HasNumeric = { x: { y: { z: number } } }\r\n\r\ntype HasString = Id\u003c{ x: { y: { z: string } } }>\r\n// ^? type HasString = { x: { y: { z: string } } }\r\n\r\nconst toDollarsAndCents = (_: HasNumeric): string => _.x.y.z.toFixed(2)\r\n\r\ndeclare const illegalValue: HasString\r\n// ^? const illegalValue: { x: { y: { z: string } } }\r\n \r\n/** 😵 */\r\ntoDollarsAndCents(illegalValue) \r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nI passed a value known by the compiler to be of type `{ x: { y: { z: string } } }` to a function expecting `{ x: { y: { z: number } } }` and did not get a compile time error warning me about it.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI expect to get a compile time error when I pass a value known by the compiler to be of type `{ x: { y: { z: string } } }` to a function expecting `{ x: { y: { z: number } } }`\r\n\r\n### Additional information about the issue\r\n\r\nHey team! First of all, thank you for your work on this project. I have used TypeScript every day for years, and since the release of v5 in particular, saw a noticeable increase in my productivity at work :)\r\n\r\nRegarding this issue, after further testing, it seems pretty trivial to reproduce with any recursive mapped type more than 2 levels deep (even with a \"no-op\" transformation, as is the case with `Id`).\r\n\r\nEven if the type were not fully instantiated, the assignability rules in this case seem to work exactly backwards from what I'd expect, which makes me think this might not be the intended behavior.\r\n\r\nThis issue might be related to #46599, which fits given that the playground's type-checker [does complain in v4.4](https://tsplay.dev/mqyqrm)\r\n\r\nLet me know if there's anything you'd like me to elaborate on!","author":{"url":"https://github.com/ahrjarrett","@type":"Person","name":"ahrjarrett"},"datePublished":"2023-08-28T01:40:17Z","url":"https://github.com/microsoft/TypeScript/issues/55535"}
| 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:f74060cf-3f40-6607-1673-9362694b1da1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEBA:172B92:256B322:31DCE85:6B01A23F |
| html-safe-nonce | 7adf910d005f026b948831e8426fa4924f244fa2138b16907c2b95dd2a6d95b0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUJBOjE3MkI5MjoyNTZCMzIyOjMxRENFODU6NkIwMUEyM0YiLCJ2aXNpdG9yX2lkIjoiNzA0NzExMzM1OTYwMjMyODEyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4b22c8ea37e374f2453a1e33c7ee3385a849a1dcc7bccd39374e7c289b2a1c3 |
| hovercard-subject-tag | issue:1868787554 |
| 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/55535/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c9fe659b1eec12125930b12ce3dd9d82c4355c5d8effa9a911ded886002f3b6/microsoft/TypeScript/issues/55535 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c9fe659b1eec12125930b12ce3dd9d82c4355c5d8effa9a911ded886002f3b6/microsoft/TypeScript/issues/55535 |
| og:image:alt | 🔎 Search Terms recursive mapped types, assignability, depth check, deeply nested 🕗 Version & Regression Information If this is in fact a bug, it looks like it was introduced in v4.5 This can cause ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ahrjarrett |
| 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