Title: Undetected illegal assignment of nested array types · Issue #52912 · microsoft/TypeScript · GitHub
Open Graph Title: Undetected illegal assignment of nested array types · Issue #52912 · microsoft/TypeScript
X Title: Undetected illegal assignment of nested array types · Issue #52912 · microsoft/TypeScript
Description: Bug Report Typescript does not allow the assignment of Source4 to Target4 which is expected because they are incompatible. After 3 or more levels of nested array properties this error is not detected anymore. Even the errors on the neste...
Open Graph Description: Bug Report Typescript does not allow the assignment of Source4 to Target4 which is expected because they are incompatible. After 3 or more levels of nested array properties this error is not detect...
X Description: Bug Report Typescript does not allow the assignment of Source4 to Target4 which is expected because they are incompatible. After 3 or more levels of nested array properties this error is not detect...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/52912
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Undetected illegal assignment of nested array types","articleBody":"# Bug Report\r\n\r\nTypescript does not allow the assignment of `Source4` to `Target4` which is expected because they are incompatible. After 3 or more levels of nested array properties this error is not detected anymore. Even the errors on the nested types may disappear depending on the order of the assignments.\r\n\r\nNote: every type is explicitly named and there are no cycles.\r\n\r\n(This actually caused problems in our production codebase)\r\n\r\n### 🔎 Search Terms\r\n\r\nnested array assignment, undetected illegal assignment of nested array types, undetected illegal assignment, illegal assignment\r\n \r\n### 🕗 Version & Regression Information\r\n\r\n- In versions before 4.5.3: limit of nested array levels is 5 instead of 3\r\n- This changed between versions 4.4.4 and 4.5.3 (to 3 levels)\r\n- PRs: \r\n - bisect: #46974 (thank you @pyBlob for bisect)\r\n - main: #46599\r\n - maybe: `isDeeplyNestedType` maxDepth check?\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.0.0-dev.20230222#code/C4TwDgpgBAyg9gVwE4GMIEYoF4oG8oCGSSBIAXLIqhAEwDaAulAL4DcAUKJJcmjdnkLFSFeLwgBmRiw5doY6hIH4iJcj2oAWaW07h5VNJuW72AejNQAzgQC20AlY1oocpwCMEwKAHcAlsAAFlAARFZw9gByED4ACkhwkEigIXrcACpEAOYQwJg4uOxQQmoUmUg5wPQMHMUW1hEQ0XEJSaAUVsBIfgB2WVD1EMRwSFC9rtm5mI5Wflk99j3ejlAQAB6QKMAQACZjAGarPQTuADa77LpyUOWV-AVFJSI3k8BSNY-14VEx8YlD7WsXV6-UGw1G42Ar2mVlm80Wyyc6022z2fkOEGOZwuV30LwquSUD2Kqmet1y2g+dUs3yav1aAPUnW6fQGliGCQhPQmBLyhFhcwWmMRqw2EC2uwORxO5x2l1kePJwGMxIaPxa-2STOBfVYbKgPTg3nWfk6ILG3IURmwAD4DXBVuCLTzKjC4UKlvL2OwduLTkRoCg4D1Og1xOhRIYMBxfSh-UhA8HQ+FxDRI6mY36A1AgyHvCnFOnFJm49nc8mo5oi0YOOZLEFTdZAohTntDd4g7YwH5zmR2OXvFDeRH8a6BAW0Og9fVOwjXIFG6detBgA7Ko7OU5Ia8aAAaF2E-nuhFOEZQWxwABuK4XTiXPQc+22oyHdyPgoR3vqDacVmbCFbe0Owibte37JNBx3Mod3HKMaGndknXRA8+RmD9hTGJxZ2FSUzwIJ8hnnRs0PhYUv3rW8mxbNsjRzECewgPsBxQiRoN5Ikw2LfUOTPZDXymd9SKWTC6NsBFcNGfDnxQ-gSI9YByKgHY4AgJx21E0DGPAvMUKrUcKVg8RNAQjc8KRMUJTlcwACp2FiGA+wAWmsOxoAACh8BI+gASigdwIECAhLz8M9-CCC1n32Ag0CcAgej2UtYVU9hrLMdggA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype Source1 = { array: Source2[] };\r\ntype Source2 = { array: Source3[] };\r\ntype Source3 = { array: Source4[] };\r\ntype Source4 = {};\r\n\r\n// same as Source types but with \"someNewProperty\"\r\ntype Target1 = {\r\n array: Target2[];\r\n // someNewProperty: string // error in target1 assignment as expected if enabled\r\n};\r\ntype Target2 = {\r\n array: Target3[];\r\n // someNewProperty: string // error in target1 assignment as expected if enabled\r\n};\r\ntype Target3 = {\r\n array: Target4[];\r\n // someNewProperty: string // error in target1 assignment as expected if enabled\r\n};\r\ntype Target4 = {\r\n someNewProperty: string; // not existing in Source4 => no error in target1 assignment\r\n};\r\n\r\ndeclare const source1: Source1;\r\ndeclare const source2: Source2;\r\ndeclare const source3: Source3;\r\ndeclare const source4: Source4;\r\n\r\n// this should not compile:\r\nconst target1: Target1 = source1; // comment this line to get errors in target2, target3 assignments or move this line after target2 assignment\r\n\r\n// this should not compile:\r\nconst target2: Target2 = source2; // error if target1 assignment is commented or after this assignment\r\n\r\n// this should not compile:\r\nconst target3: Target3 = source3; // error if target1 assignment is commented or after target2 assignment\r\n\r\n// does not compile:\r\nconst target4: Target4 = source4; // error as expected\r\n\r\n/*\r\nPS:\r\n- same (wrong) behavior with interfaces and classes\r\n*/\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n- `Source1` is assignable to `Target1`\r\n- `Source2` is assignable to `Target2`\r\n- `Source3` is assignable to `Target3`\r\n- Reordering of assignments impact type checking\r\n - If `source1` assignment is skipped or moved after `source2` assignment the expected errors show\r\n\r\n### 🙂 Expected behavior\r\n\r\n- `Source1` is **_not_** assignable to `Target1`\r\n```\r\nType 'Source1' is not assignable to type 'Target1'.\r\n Types of property 'array' are incompatible.\r\n Type 'Source2[]' is not assignable to type 'Target2[]'.\r\n Type 'Source2' is not assignable to type 'Target2'.\r\n Types of property 'array' are incompatible.\r\n Type 'Source3[]' is not assignable to type 'Target3[]'.\r\n Type 'Source3' is not assignable to type 'Target3'.\r\n Types of property 'array' are incompatible.\r\n Type 'Source4[]' is not assignable to type 'Target4[]'.\r\n Property 'someNewProperty' is missing in type 'Source4' but required in type 'Target4'.\r\n```\r\n\r\n- Since `Source1` is a fixed/static tree (without any self references) I expect the error to be found by the compiler.\r\n- Reordering of assignments do not impact type checking results\r\n\r\n### Related issues\r\nhttps://github.com/microsoft/TypeScript/issues/42070","author":{"url":"https://github.com/martinwepner","@type":"Person","name":"martinwepner"},"datePublished":"2023-02-22T12:04:56Z","url":"https://github.com/microsoft/TypeScript/issues/52912"}
| 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:7472a5cb-3550-c2ec-0128-22fea8df6ec4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD88:1050BD:86ADEE:B22EF1:6B01B0DF |
| html-safe-nonce | b6a5827492f7872d8e9186d1e7e3a9379140b701c7f09d14ff915c375b3bdfe8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDg4OjEwNTBCRDo4NkFERUU6QjIyRUYxOjZCMDFCMERGIiwidmlzaXRvcl9pZCI6Ijg5NTk1MDY4NzAyMzQ2MjQyMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a3ea45084209464e8fbc1e89cdb506e9a8c0d61afdba6852e761fdda1c685aac |
| hovercard-subject-tag | issue:1594988306 |
| 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/52912/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ea2a58bbcb0a0f199905c404588160d6ce7d810fb886d0626196608acd83d4b8/microsoft/TypeScript/issues/52912 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ea2a58bbcb0a0f199905c404588160d6ce7d810fb886d0626196608acd83d4b8/microsoft/TypeScript/issues/52912 |
| og:image:alt | Bug Report Typescript does not allow the assignment of Source4 to Target4 which is expected because they are incompatible. After 3 or more levels of nested array properties this error is not detect... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | martinwepner |
| 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