Title: TSC watch / Out of memory errors with recursive template literal types · Issue #47419 · microsoft/TypeScript · GitHub
Open Graph Title: TSC watch / Out of memory errors with recursive template literal types · Issue #47419 · microsoft/TypeScript
X Title: TSC watch / Out of memory errors with recursive template literal types · Issue #47419 · microsoft/TypeScript
Description: Bug Report When using watch and template literal recursion, TSC tends to run out of memory. How soon depends on the platform and memory size, but on a powerful Silicon Mac , it takes 2-3 modifications to the code base. On a memory-limite...
Open Graph Description: Bug Report When using watch and template literal recursion, TSC tends to run out of memory. How soon depends on the platform and memory size, but on a powerful Silicon Mac , it takes 2-3 modificati...
X Description: Bug Report When using watch and template literal recursion, TSC tends to run out of memory. How soon depends on the platform and memory size, but on a powerful Silicon Mac , it takes 2-3 modificati...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47419
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TSC watch / Out of memory errors with recursive template literal types","articleBody":"# Bug Report\r\n\r\nWhen using watch and template literal recursion, TSC tends to run out of memory. How soon depends on the platform and memory size, but on a powerful Silicon Mac , it takes 2-3 modifications to the code base. On a memory-limited Ubuntu VM, a single save after the initial compilation will error out.\r\n\r\n### 🔎 Search Terms\r\n\r\nwatch\r\nrecursion\r\ntemplate literal types\r\nmemory\r\nheap\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nTested with 4.4, 4.5, and nightly. Happens in all, consistently.\r\n\r\nTested on MacOS Silicon and Ubuntu.\r\n\r\nPlease keep and fill in the line that best applies:\r\n- This is a crash\r\n\r\n### ⏯ Playground Link\r\nThis uses tsc watch, so a link to the playground is not possible. I provide sample code below.\r\n\r\n### 💻 Code\r\nhttps://github.com/silviogutierrez/tsc-recursion-bug\r\n\r\nUsing node 14 and yarn.\r\n\r\nTo run into the issue:\r\n1. `git clone https://github.com/silviogutierrez/tsc-recursion-bug.git`\r\n2. `yarn tsc --noEmit --watch`\r\n3. Note the initial compilation is very fast.\r\n4. Open an editor and materially change `client/routes.tsx`. Change the name, etc.\r\n5. Further compilations are slow, and eventually you'll get a massive out of memory error. \r\n\r\n### 🙁 Actual behavior\r\n\r\nOut of memory error with a long stack trace. Very little info on why.\r\n\r\n### 🙂 Expected behavior\r\n\r\nQuick compilation that takes about the same time as the initial compilation. Not only is it much slower when it does work, but it crashes eventually.\r\n\r\n### More background\r\nThe issue is caused by ExtractRouteParams in `monoroutes.tsx`. If you replace the definition with:\r\n\r\n`type ExtractRouteParams\u003cT> = any`\r\n\r\nThe problem immediately goes away. Obviously this isn't what we want. You can review `routes.tsx` to see the intent of this type. That is, to strongly type params between string and numbers.\r\n\r\nMoreover, the problem is related to `route` being a recursive function. See `routes.tsx` for an example of how it's used to create sub routes that share paths.\r\n\r\nOther things that \"fix\" the error: \r\n\r\n- Eliminate `innerRoute` from `monoroutes.tsx`, limiting routes to a single level.\r\n- Make `ExtractRouteParams` less powerful. Make it only parse params instead of string/number. Like so:\r\n- \r\n```\r\ntype ExtractRouteParams\u003cT> = string extends T\r\n ? Record\u003cstring, string | number>\r\n : T extends `${infer _Start}\u003c${infer Param}>/${infer Rest}`\r\n ? ExtractRouteParams\u003c_Start> & {[k in Param]: string} & ExtractRouteParams\u003cRest>\r\n : T extends `${infer _Start}\u003c${infer Param}>`\r\n ? {[k in Param]: string}\r\n : {};\r\n```\r\n\r\nHappy to provide more context. Normally I would say this is a real edge case, but the fact that it *only* affects `watch` functionality and not the initial compile leads me to believe it needs to be addressed. Thanks for all the work on typescript!","author":{"url":"https://github.com/silviogutierrez","@type":"Person","name":"silviogutierrez"},"datePublished":"2022-01-13T05:02:45Z","url":"https://github.com/microsoft/TypeScript/issues/47419"}
| 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:9f064aca-173b-ab19-e9e8-f65bc38761b2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 835E:E3C4F:3199596:3F4F408:6B01D8A4 |
| html-safe-nonce | 33b34cf9a04410e515913c1c2d01065a73750c19bcee4bef0893d81f29be7a06 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzVFOkUzQzRGOjMxOTk1OTY6M0Y0RjQwODo2QjAxRDhBNCIsInZpc2l0b3JfaWQiOiI0OTAwNTMwNjQ1NDE3MTg3NDkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5936c1d7b932286b02bc0063a829750c07ceb14efcfb676b10e6eeac430c2a31 |
| hovercard-subject-tag | issue:1101209938 |
| 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/47419/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a415b284d9caaee7e8dbcc3e0d72c83973f3c70e6263d8e1674c60ca68f9a5b1/microsoft/TypeScript/issues/47419 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a415b284d9caaee7e8dbcc3e0d72c83973f3c70e6263d8e1674c60ca68f9a5b1/microsoft/TypeScript/issues/47419 |
| og:image:alt | Bug Report When using watch and template literal recursion, TSC tends to run out of memory. How soon depends on the platform and memory size, but on a powerful Silicon Mac , it takes 2-3 modificati... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | silviogutierrez |
| 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