Title: Max depth limit does not trigger. Gives up and resolves type to any · Issue #32707 · microsoft/TypeScript · GitHub
Open Graph Title: Max depth limit does not trigger. Gives up and resolves type to any · Issue #32707 · microsoft/TypeScript
X Title: Max depth limit does not trigger. Gives up and resolves type to any · Issue #32707 · microsoft/TypeScript
Description: TypeScript Version: 3.5.1 Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Chaining methods Fluent API Generic class Generic method Code Using DataT, type AppendToArray
Open Graph Description: TypeScript Version: 3.5.1 Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Chaining methods Fluent API Generic class Generic method Code Using DataT, type AppendT...
X Description: TypeScript Version: 3.5.1 Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Chaining methods Fluent API Generic class Generic method Code Using DataT, type AppendT...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32707
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Max depth limit does not trigger. Gives up and resolves type to any","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.5.1\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\n\r\n+ Type instantiation is excessively deep and possibly infinite.ts(2589)\r\n+ Chaining methods\r\n+ Fluent API\r\n+ Generic class\r\n+ Generic method\r\n\r\n**Code**\r\n\r\nUsing `DataT`,\r\n```ts\r\ntype AppendToArray\u003cArrT extends any[], T> = (\r\n (\r\n ArrT[number]|\r\n T\r\n )[]\r\n);\r\ninterface Data {\r\n arr : number[]\r\n};\r\ntype AppendToFoo\u003cC extends Data, N extends number> = (\r\n Foo\u003c{arr:AppendToArray\u003cC[\"arr\"], N>}>\r\n);\r\n\r\nclass Foo\u003cDataT extends Data> {\r\n arr! : DataT[\"arr\"];\r\n //Using `DataT`\r\n x\u003cN extends number> (n:N) : AppendToFoo\u003cDataT, N> {\r\n return null!;\r\n }\r\n}\r\ndeclare const foo0 : Foo\u003c{arr:0[]}>;\r\n/*\r\nconst foo12: Foo\u003c{\r\n arr: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12)[];\r\n}>\r\n*/\r\nconst foo12 = foo0\r\n .x(1).x(2).x(3).x(4).x(5).x(6).x(7).x(8).x(9).x(10).x(11).x(12);\r\n/*\r\nExpected:\r\n\r\n+ Similar to foo12\r\nOR\r\n+ Type instantiation is excessively deep and possibly infinite.ts(2589)\r\n\r\nActual:\r\nconst foo13: Foo\u003c{\r\n arr: any[];\r\n}>\r\n*/\r\nconst foo13 = foo12.x(13);\r\n```\r\n\r\n[Playground](http://www.typescriptlang.org/play/#code/C4TwDgpgBAgmkDsAmAVA9jATpghiAPFpilBAB7ATIDOUOCIA2gLoA0UKAfFALxQAUAKCgiBw0RKIpGCAK4BbAEYRMzAD7iJIlJqgBKFoL0BuQQEsElTADMcAY2gARHMBxQA3rpzYoALihySiqGAL6moJCw8FSoaABiaGj4AMKkFDG0zq7sAHJplDQBCsqY3HxCEglJ7t6YvnCIsUR4KYwARLVtbFA5nCGcRqaCdgA2ONS0VfhZOCTkBUiZLjjcnhK1AIR+UDPSHdhdphIA9McAqtQWAOZQAAa7t7pk+HnzGUVBpQIIvjl62w0YugprtcqtdBJMBBgLJMAgiiMRhsjqIQoI0UgIKNvNA7GgENRgFBrIkAAzbKY1bC+UksfqmY4AKmG+MJxMSAEYAEz+SleakCclqKAcqDCrliqAAZklABZJQBWSUANklAHZJQAOSUATklHKFItFwu5BmYpn6gkZxxZBKJJLQ3N47LQpN0ADoyPwOXpPfwub6vVLA-xZSGFSHlSG1SHNSGdSGDYmfX7TQzmQBRMiQOyUJC+QSCADUUAAymZ5GYxpgoMA0C7uYIAPIAJWLHHA0AshPowDMLjM+KgZlo5AcEzMADcICMQFBMRAwHRkFAwGgJ4pZ8OENYLGZKO7gNR-QrNQnCzBc7IcCMC3i7Q2pbzEvg1qJav56ExzeiBtbbWyDocjKfBAVyqbBsYQA)\r\n\r\nUsing `this`,\r\n```ts\r\ntype AppendToArray\u003cArrT extends any[], T> = (\r\n (\r\n ArrT[number]|\r\n T\r\n )[]\r\n);\r\ninterface Data {\r\n arr : number[]\r\n};\r\ntype AppendToFoo\u003cC extends Data, N extends number> = (\r\n Foo\u003c{arr:AppendToArray\u003cC[\"arr\"], N>}>\r\n);\r\n\r\nclass Foo\u003cDataT extends Data> {\r\n arr! : DataT[\"arr\"];\r\n //Using `this`\r\n x\u003cN extends number> (n:N) : AppendToFoo\u003cthis, N> {\r\n return null!;\r\n }\r\n}\r\ndeclare const foo0 : Foo\u003c{arr:0[]}>;\r\n/*\r\nconst foo9: Foo\u003c{\r\n arr: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)[];\r\n}>\r\n*/\r\nconst foo9 = foo0\r\n .x(1).x(2).x(3).x(4).x(5).x(6).x(7).x(8).x(9);\r\n/*\r\nExpected:\r\n\r\n+ Similar to foo9\r\nOR\r\n+ Type instantiation is excessively deep and possibly infinite.ts(2589)\r\n\r\nActual:\r\nconst foo10: Foo\u003c{\r\n arr: any[];\r\n}>\r\n*/\r\nconst foo10 = foo9.x(10);\r\n```\r\n\r\n[Playground](http://www.typescriptlang.org/play/#code/C4TwDgpgBAgmkDsAmAVA9jATpghiAPFpilBAB7ATIDOUOCIA2gLoA0UKAfFALxQAUAKCgiBw0RKIpGCAK4BbAEYRMzAD7iJIlJqgBKFoL0BuQQEsElTADMcAY2gARHMBxQA3rpzYoALihySiqGAL6moJCw8FSoaABiaGj4AMKkFDG0zq7sAHJplDQBCsqY3HxCEglJ7t6YvnCIsUR4KYwARLVtbFA5nCGcRqaCdgA2ONS0VfhZOCTkBUiZLjjcnhK1AIR+UDPSHdhdphIA9McAqtQWAOZQAAbAABZm1Le6ZPh58xlFQaUCCL4cnptg0Yugpo9nrlVroJJgIMBZJgEEURiMNkdRCFBNikBBRt5oHY0AhqMAoNZEgAGbZTGrYXxUlj9UzHABUwxJZIpiQAnP46V4GQIaWooABGKBigBMUqgAGY5QAWOUAVjlADY5QB2OUADjlvIMzFM-UEbOOnNJ5MpaF5vB5aCpugAdGR+OK9G7+NKve75X7+ErA6rAxrA9rA3rA0bWRyAKJkSB2ShIXyCQQAaigAGUzPIzGNMFBgGhHbzBAB5ABKWY44GgFjJ9GAZhcZhJUGeaQcEzMADcICMQFA8RAwHRkFAwGg+4ph12ENYLGZKC7gNQfaq9UaMzAU7IcCN08TrY7xVSBYl8GtRLV-PQmCacQMLVbubaLw7bbzvReTEAA)\r\n\r\n**Expected behavior:**\r\n\r\nBoth examples should resolve correctly or trigger, `Type instantiation is excessively deep and possibly infinite.ts(2589)`\r\n\r\nSee code for more details.\r\n\r\n**Actual behavior:**\r\n\r\nBoth examples resolve to `any` without errors.\r\nBoth examples seem to have a different limit before this happens?\r\n\r\nSee code for more details.\r\n\r\n**Playground Link:** \r\n\r\nUsing `DataT`, the limit seems to be `12`.\r\n\r\n[Playground](http://www.typescriptlang.org/play/#code/C4TwDgpgBAgmkDsAmAVA9jATpghiAPFpilBAB7ATIDOUOCIA2gLoA0UKAfFALxQAUAKCgiBw0RKIpGCAK4BbAEYRMzAD7iJIlJqgBKFoL0BuQQEsElTADMcAY2gARHMBxQA3rpzYoALihySiqGAL6moJCw8FSoaABiaGj4AMKkFDG0zq7sAHJplDQBCsqY3HxCEglJ7t6YvnCIsUR4KYwARLVtbFA5nCGcRqaCdgA2ONS0VfhZOCTkBUiZLjjcnhK1AIR+UDPSHdhdphIA9McAqtQWAOZQAAa7t7pk+HnzGUVBpQIIvjl62w0YugprtcqtdBJMBBgLJMAgiiMRhsjqIQoI0UgIKNvNA7GgENRgFBrIkAAzbKY1bC+UksfqmY4AKmG+MJxMSAEYAEz+SleakCclqKAcqDCrliqAAZklABZJQBWSUANklAHZJQAOSUATklHKFItFwu5BmYpn6gkZxxZBKJJLQ3N47LQpN0ADoyPwOXpPfwub6vVLA-xZSGFSHlSG1SHNSGdSGDYmfX7TQzmQBRMiQOyUJC+QSCADUUAAymZ5GYxpgoMA0C7uYIAPIAJWLHHA0AshPowDMLjM+KgZlo5AcEzMADcICMQFBMRAwHRkFAwGgJ4pZ8OENYLGZKO7gNR-QrNQnCzBc7IcCMC3i7Q2pbzEvg1qJav56ExzeiBtbbWyDocjKfBAVyqbBsYQA)\r\n\r\nUsing `this`, the limit seems to be `9`.\r\n\r\n[Playground](http://www.typescriptlang.org/play/#code/C4TwDgpgBAgmkDsAmAVA9jATpghiAPFpilBAB7ATIDOUOCIA2gLoA0UKAfFALxQAUAKCgiBw0RKIpGCAK4BbAEYRMzAD7iJIlJqgBKFoL0BuQQEsElTADMcAY2gARHMBxQA3rpzYoALihySiqGAL6moJCw8FSoaABiaGj4AMKkFDG0zq7sAHJplDQBCsqY3HxCEglJ7t6YvnCIsUR4KYwARLVtbFA5nCGcRqaCdgA2ONS0VfhZOCTkBUiZLjjcnhK1AIR+UDPSHdhdphIA9McAqtQWAOZQAAbAABZm1Le6ZPh58xlFQaUCCL4cnptg0Yugpo9nrlVroJJgIMBZJgEEURiMNkdRCFBNikBBRt5oHY0AhqMAoNZEgAGbZTGrYXxUlj9UzHABUwxJZIpiQAnP46V4GQIaWooABGKBigBMUqgAGY5QAWOUAVjlADY5QB2OUADjlvIMzFM-UEbOOnNJ5MpaF5vB5aCpugAdGR+OK9G7+NKve75X7+ErA6rAxrA9rA3rA0bWRyAKJkSB2ShIXyCQQAaigAGUzPIzGNMFBgGhHbzBAB5ABKWY44GgFjJ9GAZhcZhJUGeaQcEzMADcICMQFA8RAwHRkFAwGg+4ph12ENYLGZKC7gNQfaq9UaMzAU7IcCN08TrY7xVSBYl8GtRLV-PQmCacQMLVbubaLw7bbzvReTEAA)\r\n\r\n**Related Issues:** \r\n\r\nI have no clue how to search for this.\r\n\r\n-----\r\n\r\nI came across this weird bug by accident, actually.\r\n\r\nI was working on a personal project and this would be the 4th, or 6th time I've rewritten the project. I've noticed that in all the rewrites, there's this particular method on generic class where the max number of times I could chain it was always 20.\r\n\r\nThe 21st call would always trigger the max depth error.\r\n\r\nI was sick of it and decided to investigate possible ways to work around this limit.\r\n\r\nI decided to write a simple repro before messing with it. (The above code snippets).\r\nHowever, the simplified repro behaved **very** weirdly, and would not trigger the error.\r\n\r\nIt boggles me how TS can resolve crazy types like [this](http://www.typescriptlang.org/play/#code/C4TwDgpgBAgmkDsAmAeGAndAVKEAewEyAzlAIYIgDaAugDRRYB8UAvFABQBQUvnPfQRmxUEAVwC2AIwjoaAHwGDeWJVACUtLuoDcXLgGMANmWKkAGmkw58hEuUq0WAbzXAAhFABcsa3sF4nOreUJZwiKjCWAxRTC5qgugQwGLoCFAIEADuoRy6agC+XEVIEMZkSVAGAPYIxMBQgT6WTno1dQ3obI0AdHh5fQP96oMjw6MT41NDM2Ozk-PTc+pcC8trG0ubizvrw6tbh7vbe8dHpxcnV+fXZ3eXN4+7B-e3D69Pyy-vP29rXEA),\r\n\r\n\r\n\r\nbut will choke on simple types like the above snippets.\r\n\r\n-----\r\n\r\nIt's also super weird because my super complex examples have a limit of 20 calls. And these super simple examples have a super low limit.","author":{"url":"https://github.com/AnyhowStep","@type":"Person","name":"AnyhowStep"},"datePublished":"2019-08-05T05:53:05Z","url":"https://github.com/microsoft/TypeScript/issues/32707"}
| 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:29f0f559-11bf-b022-0a22-58705a198b68 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7F0:F7C4C:25DDB4A:32B7D24:6B01AD66 |
| html-safe-nonce | 6ed123a1cb570baa537a769c6ff5d508161ddde2431e2cf5c76137eb74f222d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0YwOkY3QzRDOjI1RERCNEE6MzJCN0QyNDo2QjAxQUQ2NiIsInZpc2l0b3JfaWQiOiI1Njg2NTk3NDc1NDg2NTEwNDM4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 740e8a31f3ea5418a651dcef9fccea91d4a3d998ae5eefb48feee72e5b020090 |
| hovercard-subject-tag | issue:476669188 |
| 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/32707/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4a89299b4ccbbfb218d4a4fd6d2ad37579313a6fcb4e715c989a2e4d208c911b/microsoft/TypeScript/issues/32707 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4a89299b4ccbbfb218d4a4fd6d2ad37579313a6fcb4e715c989a2e4d208c911b/microsoft/TypeScript/issues/32707 |
| og:image:alt | TypeScript Version: 3.5.1 Search Terms: Type instantiation is excessively deep and possibly infinite.ts(2589) Chaining methods Fluent API Generic class Generic method Code Using DataT, type AppendT... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AnyhowStep |
| 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