Title: 7.1 regression: bounded recursive types report TS5115 when inferred through a closure · Issue #65440 · microsoft/TypeScript · GitHub
Open Graph Title: 7.1 regression: bounded recursive types report TS5115 when inferred through a closure · Issue #65440 · microsoft/TypeScript
X Title: 7.1 regression: bounded recursive types report TS5115 when inferred through a closure · Issue #65440 · microsoft/TypeScript
Description: 🔎 Search Terms TS5115, TS2589, "appear infinitely circular", "excessively deep and possibly infinite", variance, closure, 4820 🕗 Version & Regression Information This changed between versions 7.1.0-dev.20260805.1 and 7.1.0-dev.20260806.1...
Open Graph Description: 🔎 Search Terms TS5115, TS2589, "appear infinitely circular", "excessively deep and possibly infinite", variance, closure, 4820 🕗 Version & Regression Information This changed between versions 7.1.0...
X Description: 🔎 Search Terms TS5115, TS2589, "appear infinitely circular", "excessively deep and possibly infinite", variance, closure, 4820 🕗 Version & Regression Information This change...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/65440
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"7.1 regression: bounded recursive types report TS5115 when inferred through a closure","articleBody":"### 🔎 Search Terms\n\nTS5115, TS2589, \"appear infinitely circular\", \"excessively deep and possibly infinite\", variance, closure, 4820\n\n### 🕗 Version & Regression Information\n\n- This changed between versions `7.1.0-dev.20260805.1` and `7.1.0-dev.20260806.1`. The only commit between them is microsoft/typescript-go#4820 \"Order variance computation by associated type symbol\".\n- `7.1.0-dev.20260806.1` reports TS2589. Since #64372 (`7.1.0-dev.20260929.1`), the same error is reported as TS5115.\n- `7.0.2` and `7.1.0-dev.20260805.1` report nothing. Still present in `7.1.0-beta` and `7.1.0-dev.20261111.1`.\n- This is not the case of #64605: there is no base type argument that refers back to its own type, and the error starts before #64372.\n\n### ⏯ Playground Link\n\nRepository with every version pinned: https://github.com/RomainLanz/tsrs-type-issue (npm install && npm run check:all)\n\n### 💻 Code\n\nThe types are reduced from [@adonisjs/http-transformers](https://www.npmjs.com/package/@adonisjs/http-transformers) 2.3.1, with no dependencies. strict, target: esnext.\n\n```ts\ntype Prettify\u003cT> = { [K in keyof T]: T[K] } & {};\ntype ExtractUndefined\u003cT> = { [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];\ntype ExtractDefined\u003cT> = { [K in keyof T]: undefined extends T[K] ? never : K }[keyof T];\ntype Next = [1, 2, 3, 4, 5, 6];\ntype JSONPrimitives = string | number | bigint | boolean | null | undefined;\ntype JSONValues = JSONPrimitives | CanBeSerialized\u003cany>;\ntype CanBeSerialized\u003cT extends JSONDataTypes> = {\n toJSON(): T;\n};\ntype JSONDataTypes = JSONValues | JSONDataTypes[] | {\n [key: string]: JSONDataTypes;\n};\ntype SerializeJSONObject\u003cT> = {\n [K in ExtractDefined\u003cT>]: SerializeJSONTypes\u003cT[K]>;\n} & {\n [K in ExtractUndefined\u003cT>]?: SerializeJSONTypes\u003cT[K]>;\n};\ninterface ExtendedJSONTypes {\n}\ntype NonAllowedJSTypes = Map\u003cany, any> | Set\u003cany>;\ntype ForcefullyAllowedTypes = {\n [K in keyof ExtendedJSONTypes]: ExtendedJSONTypes[K];\n}[keyof ExtendedJSONTypes];\ntype SerializeJSONOwnTypes\u003cT> = T extends JSONPrimitives ? T : T extends ForcefullyAllowedTypes ? T : T extends NonAllowedJSTypes ? never : T extends Array\u003cinfer item> ? Array\u003cSerializeJSONTypes\u003citem>> : T extends object ? Prettify\u003cSerializeJSONObject\u003cT>> : never;\ntype SerializeJSONTypes\u003cT> = T extends ForcefullyAllowedTypes ? T : T extends CanBeSerialized\u003cinfer A> ? SerializeJSONOwnTypes\u003cA> : SerializeJSONOwnTypes\u003cT>;\ninterface ItemContract\u003cTransformer extends Record\u003cstring, any>, MaxDepth extends Next[number], Variant extends string> {\n $type: 'item';\n transformer: {\n new (...args: any[]): Transformer;\n };\n maxDepth: MaxDepth;\n variant: Variant;\n}\ntype UnpackKeyValue\u003cValue extends [any, any], MaxDepth extends number, Depth extends number> = [Value[0]] extends [never] ? SerializeJSONTypes\u003cValue[1]> : Value[0] extends ItemContract\u003cinfer Transformer, infer LocalMaxDepth, infer Variant> ? InferData\u003cTransformer, Variant, MaxDepth extends -1 ? LocalMaxDepth : MaxDepth, Next[Depth]> | SerializeJSONTypes\u003cValue[1]> : SerializeJSONTypes\u003cValue[1]>;\ntype LimitDepth\u003cKey, Value, MaxDepth extends number, Depth extends number> = [\n Value\n] extends [never] ? Key : Value extends ItemContract\u003cany, any, any> ? MaxDepth extends Depth ? never : Key : Key;\ntype UnpackOptionalValues\u003cData, MaxDepth extends number, Depth extends number> = {\n [O in {\n [K in keyof Data]: [undefined] extends [Data[K]] ? LimitDepth\u003cK, SplitItm\u003cData[K]>[0], MaxDepth, Depth> : never;\n }[keyof Data]]?: UnpackKeyValue\u003cSplitItm\u003cData[O]>, MaxDepth, Depth>;\n};\ntype UnpackRequiredValues\u003cData, MaxDepth extends number, Depth extends number> = {\n [O in {\n [K in keyof Data]: [undefined] extends [Data[K]] ? never : LimitDepth\u003cK, SplitItm\u003cData[K]>[0], MaxDepth, Depth>;\n }[keyof Data]]: UnpackKeyValue\u003cSplitItm\u003cData[O]>, MaxDepth, Depth>;\n};\ntype SplitItm\u003cT> = [\n Extract\u003cT, ItemContract\u003cany, any, any>>,\n Exclude\u003cT, ItemContract\u003cany, any, any>>\n];\ntype UnpackAsTopLevelItem\u003cT, Wrapper extends string | undefined> = T extends ItemContract\u003cinfer Transformer, any, infer Variant> ? InferData\u003cTransformer, Variant, -1, 0> : never;\ntype UnpackValues\u003cData, MaxDepth extends number, Depth extends number> = Prettify\u003cUnpackRequiredValues\u003cData, MaxDepth, Depth> & UnpackOptionalValues\u003cData, MaxDepth, Depth>>;\ntype InferData\u003cTransformer, Variant extends string = 'toObject', MaxDepth extends number = -1, Depth extends number = 0> = Transformer extends {\n [K in Variant]: (...args: any[]) => unknown;\n} ? UnpackValues\u003cAwaited\u003cReturnType\u003cTransformer[Variant]>>, MaxDepth, Depth> : never;\ndeclare class Item\u003cTransformer extends Record\u003cstring, any>, MaxDepth extends Next[number], Variant extends string> {\n\ttransformer: { new (...args: any[]): Transformer };\n\tmaxDepth: MaxDepth;\n\tvariant: Variant;\n\t$type: 'item';\n\tresolve(): Promise\u003cUnpackAsTopLevelItem\u003cthis, undefined>>;\n}\ntype Ctor = { new (resource: any, ...rest: any[]): any };\ndeclare abstract class BaseTransformer\u003cT> {\n\tstatic transform\u003cSelf extends Ctor>(this: Self, data: ConstructorParameters\u003cSelf>[0]): Item\u003cInstanceType\u003cSelf>, 1, 'toObject'>;\n\tconstructor(resource: T);\n}\nclass Size {\n}\nclass SizeTransformer extends BaseTransformer\u003cSize> {\n\ttoObject() {\n\t}\n}\ndeclare function once\u003cT>(value: T): T;\nonce(() => SizeTransformer.transform(new Size()));\n```\n\n\n### 🙁 Actual behavior\n\n```sh\nrepro.ts(76,12): error TS5115: Instantiations of the following types appear infinitely circular: 'InferData', 'UnpackKeyValue'.\n```\n\nWith 7.1.0-dev.20260806.1 to 7.1.0-dev.20260928.1:\n\n```sh\nrepro.ts(76,12): error TS2589: Type instantiation is excessively deep and possibly infinite.\n```\n\n### 🙂 Expected behavior\n\nNo error, as in 7.0.2 and 7.1.0-dev.20260805.1. The recursion is bounded: each `UnpackKeyValue` → `InferData` step advances `Depth` through `Next = [1, 2, 3, 4, 5, 6]`. `toObject()` here returns void, so there is not even a property to recurse into.\n\n### Additional information about the issue\n\nThe error depends on how the value reaches the generic call. Passing the `Item` directly checks without error on every version:\n\n```ts\nonce(() => SizeTransformer.transform(new Size())); // TS5115\nonce(SizeTransformer.transform(new Size())); // no error\n```\n\nMy guess, not verified: microsoft/typescript-go#4820 restarts variance computations from the earliest declared symbol when it detects a circularity, and the inference of the closure's return type may now reach that restart through `InferData` and `UnpackKeyValue`. We found it on a real AdonisJS application; `tsrs`, which ports 7.1, reports the same error.","author":{"url":"https://github.com/RomainLanz","@type":"Person","name":"RomainLanz"},"datePublished":"2026-11-11T10:49:41Z","url":"https://github.com/microsoft/TypeScript/issues/65440"}
| 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:f340d184-a97d-ae4a-721f-5a8addda1049 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3E4:1C6C3E:D2F4A0:11739D6:6B00F8D8 |
| html-safe-nonce | b2611e4205ff6c9d616cebb2d01f22e3aaf6f6e4388463e48b52972c73f6324d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0U0OjFDNkMzRTpEMkY0QTA6MTE3MzlENjo2QjAwRjhEOCIsInZpc2l0b3JfaWQiOiIxMzM4MDE4NzA5Nzc1NjQ0ODg4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b559824407ba0afb80f57352c9ff850ea487b8acbbebde0ed128e0ff4ee8936f |
| hovercard-subject-tag | issue:6326821041 |
| 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/65440/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53b484ed1cad3148d1ac0ffc1dfb1a7af00fb2b471e36ee5194fea4cb62bf8ba/microsoft/TypeScript/issues/65440 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53b484ed1cad3148d1ac0ffc1dfb1a7af00fb2b471e36ee5194fea4cb62bf8ba/microsoft/TypeScript/issues/65440 |
| og:image:alt | 🔎 Search Terms TS5115, TS2589, "appear infinitely circular", "excessively deep and possibly infinite", variance, closure, 4820 🕗 Version & Regression Information This changed between versions 7.1.0... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RomainLanz |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width