Title: TS7 regression: callback parameter loses contextual type (TS7006) for a computed `string` key when the type parameter's constraint references itself · Issue #65530 · microsoft/TypeScript · GitHub
Open Graph Title: TS7 regression: callback parameter loses contextual type (TS7006) for a computed `string` key when the type parameter's constraint references itself · Issue #65530 · microsoft/TypeScript
X Title: TS7 regression: callback parameter loses contextual type (TS7006) for a computed `string` key when the type parameter's constraint references itself · Issue #65530 · microsoft/TypeScript
Description: 🔎 Search Terms TS7006, implicitly has an 'any' type, contextual type, computed property name, string index signature, self-referential constraint, R extends F
Open Graph Description: 🔎 Search Terms TS7006, implicitly has an 'any' type, contextual type, computed property name, string index signature, self-referential constraint, R extends F
X Description: 🔎 Search Terms TS7006, implicitly has an 'any' type, contextual type, computed property name, string index signature, self-referential constraint, R extends F<R>, circular constraint,...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/65530
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS7 regression: callback parameter loses contextual type (TS7006) for a computed `string` key when the type parameter's constraint references itself","articleBody":"### 🔎 Search Terms\n\nTS7006, implicitly has an 'any' type, contextual type, computed property name, string index signature, self-referential constraint, `R extends F\u003cR>`, circular constraint, 7.0 regression\n\n### 🕗 Version & Regression Information\n\n- This changed between versions 6.0.3 and 7.0.1-rc.\n- It still happens on 7.1.0-dev.20261116.1 (`typescript@next`).\n\n| Version | `tsc -p` result |\n| -------------------- | --------------- |\n| 5.9.3 | no errors |\n| 6.0.3 | no errors |\n| 7.0.1-rc | TS7006 |\n| 7.0.2 | TS7006 |\n| 7.1.0-beta | TS7006 |\n| 7.1.0-dev.20261116.1 | TS7006 |\n\nIt doesn't depend on parallel checking: 7.0.2 reports the same TS7006 with `--singleThreaded` and with `--checkers 1`, `2`, and `8`, and `next` reports it in 10 of 10 runs of a single-file version.\n\n### ⏯ Playground Link\n\nPlayground v2, same project on both versions:\n\n- [6.0.3](https://www.typescriptlang.org/play/v2/?ts=6.0.3#code/v2/N4IghgxgLglgbgUwGIwDYJ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TS7006 at `main.ts:5:33`.\n\nThe links carry a `tsconfig.json` with `\"include\": [\"*.ts\"]`, because the v2 default config only includes `./src`.\n\n**Note on TS2313.** The types in `lib.d.ts` contain a circular constraint (details below). The repro models a library: the types ship as a `.d.ts`, and the call sits in the consumer's code. That's the setup where this was found. A consumer never sees the circularity error:\n\n- With `skipLibCheck: true`, the `.d.ts` isn't checked, so its TS2313 is never reported. That holds on every version and in any check order.\n- With `skipLibCheck: false`, `tsc` still doesn't print it, because it checks the `.d.ts` before the consumer file.\n- On 7.x, the consumer gets TS7006 in their own code, with nothing pointing at the library.\n\nIf you put the types in a `.ts` file and check the call first (a single-file repro does this), TS2313 appears on every version, 6.0.3 included. 6.0.3 still infers `el: number` in that case. So the circularity is common to both versions; only 7.x loses the contextual type. Playground with the types in `lib.ts`: [6.0.3](https://www.typescriptlang.org/play/v2/?ts=6.0.3#code/v2/N4IghgxgLglgbgUwGIwDYJALhAegO4D2ATgNYDOADpAjlGRAQHYBmMA5gHQBWZTIANCFboyWUPmLkqEGnQYt23XoywhgAAgA6IBgFsKaBEQDyFWEzLbM6jdrJQiMaFfUOArgn5aQuggBM3dBdtRn8ERgQADyhtL20oMCI2BBisbwQyCOjtdQBfOJAYRghUNz8EFwBtbQAqDjptAF08gVxCUkpqHFQYACN60WwoAE8KBHUAOQIAZQcwYYAlQIQAaQRhsgAeBYA+dQBeG3VKlfUi9RJ1gmZ1BcbrN0YSULxGPIBuTUYRsfVZx2gSxE2y8ABU9ocABSVS7Da63ZpRKDhPxkY4RRBEZoAfluCAAjm4YEQEH5NuD1NYpv95kDVustrsAJTqABkNi+6mOp3OC3USJRaMezwIr3UuIAopESmUEJtYfCFl4FTcKdYMUZGtj1QhMZ9GLl9VEKMQoOpyiVEuNLWQ0QARIzwIzkvbATnmx2Ibb86KC9Sgtl-BxOKB0xlgnY7SG9ImoPzWSEs-Z7BZM6xwAgwPz6rkUVBgIregWMVH+qMxtDx9SJg4ptPqDNZ-W5VoSDrSGi6AuMAa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Z-W5VoSDrSGi6AuMAaqGD6U2uUbjDQOxyYvLqZhEAi6bwcbp9bT6i35knqeT2C7raz2RyMNgrhCW9ebs1FcqRUnWMdOoibDSVSK74MH+7VhCodVuXS9IxJvZhReN5ch2I8T2tCwzR6ZEiDAL91FvTEH3UGc8DIbUPwQxgfz-IgAPUIDRRAsCvgvKJSQ4cpxwQSEa2TatH1hd9IU-AjPzyJkmXedQcBwf1pgAdgABmEgA2dQmHUQSOEiSTGFQYYvhgox4Koz1aPovZIQ0NCyATNja35VBOO43j+OMU5dSMYY8AACyMCpGHIq8-A4PNuzogidOOZiDNQdiTNyLieL49RLP5TFbIckkvhAfIQDIT9j3MFRMFAE0yBgVKAGECFKXQ0oARmEgBWQRMuymAmAAGSKBAJlwowsCKwQkvQaBqsYWZEigPKCuKsq2uSzqmB6ogoDqiJGt-ZrMCKhLMSyvhMAAJlyIA) shows TS2313 and TS7006.\n\n### 💻 Code\n\n```ts\n// @filename: lib.d.ts\ntype NoStrayRuleKeys\u003cR> = { [K in keyof R]: unknown };\ntype StrictRules\u003cR, T> = ([keyof R] extends [never] ? Required\u003cT> : NoStrayRuleKeys\u003cR>) & {\n [K in R extends unknown ? Exclude\u003ckeyof R, keyof T> : never]?: never;\n};\nexport declare class Deriver\u003cT> {\n derive\u003cR extends T & StrictRules\u003cR, T>>(build: () => R): void;\n plain\u003cR extends T>(build: () => R): void;\n}\n// @filename: main.ts\nimport type { Deriver } from \"./lib.js\";\ndeclare const key: string;\ndeclare const indexed: Deriver\u003c{ [x: string]: (el: number) => unknown }>;\ndeclare const literal: Deriver\u003c{ rows?: (el: number) => unknown }>;\nindexed.derive(() => ({ [key]: (el) => el })); // TS7006 on 7.x only\nliteral.derive(() => ({ rows: (el) => el })); // OK everywhere\nindexed.plain(() => ({ [key]: (el) => el })); // OK everywhere\n```\n\n`tsconfig.json`:\n\n```json\n{ \"compilerOptions\": { \"strict\": true, \"noEmit\": true, \"skipLibCheck\": true, \"target\": \"ESNext\", \"module\": \"ESNext\", \"moduleResolution\": \"bundler\", \"types\": [], \"lib\": [\"ESNext\"] }, \"files\": [\"main.ts\"] }\n```\n\nRun `npx -p typescript@7.0.2 tsc -p tsconfig.json`, then the same with `typescript@6.0.3`. The result is the same with `skipLibCheck: false`, and when `lib.d.ts` is the declaration file that 6.0.3 emits from a `lib.ts` and lives in `node_modules`.\n\n### 🙁 Actual behavior\n\nOn 7.x:\n\n```\nmain.ts(5,33): error TS7006: Parameter 'el' implicitly has an 'any' type.\n```\n\n### 🙂 Expected behavior\n\nNo errors, as on 6.0.3, where `el` is contextually typed as `number` in all three calls.\n\n### Additional information about the issue\n\n**The cycle.** `R`'s constraint is `T & StrictRules\u003cR, T>`. `StrictRules` contains a mapped type whose key set, `R extends unknown ? Exclude\u003ckeyof R, keyof T> : never`, distributes over `R`. So resolving that key's constraint needs `R`'s constraint, which contains the same mapped type. The cycle appears only when the alias is applied to `derive`'s `R`, which happens while checking the call. TS2313 is then filed against the declaring file.\n\n**What differs between 6.0.3 and 7.x.** Varying only the value type `X` of the stray-key member isolates it:\n\n```ts\ntype StrictRules\u003cR, T> = ([keyof R] extends [never] ? Required\u003cT> : NoStrayRuleKeys\u003cR>) & {\n [K in R extends unknown ? Exclude\u003ckeyof R, keyof T> : never]?: X; // X varies\n};\n```\n\n| Stray-key member | 6.0.3 | 7.x |\n| --------------------------------------------- | ------------ | ---------------------- |\n| circular keys, `X = never` (the repro) | `el: number` | TS7006 |\n| circular keys, `X = unknown` | `el: number` | `el: number` |\n| circular keys, `X = (el: string) => unknown` | `el: number` | `el: string \\| number` |\n| `[K in string]?: never` (no cycle) | TS7006 | TS7006 |\n\nThe third row shows the difference directly. On 7.x, the mapped type whose key type parameter has a circular constraint (the TS2313 one) acts as a `[x: string]` index signature when contextually typing a computed `string` key, and its parameter type merges with `T`'s index signature. On 6.0.3 it contributes nothing to that contextual type.\n\nWith `?: never`, the value is `undefined`, so the contextual type for the computed key becomes roughly `((el: number) => unknown) & undefined`. That has no call signature, so `el` becomes implicitly `any`. The last row confirms that a real `[x: string]: undefined` member produces TS7006 on both versions. A literal key (`literal.derive`) isn't affected, because `T`'s concrete `rows` property is preferred over index signatures.\n\nSo the regression seems to be in how a mapped type with a circular key constraint resolves its members on 7.x: an index signature versus no members.\n\nThe reduction is sensitive. Each of these changes alone makes 7.x behave like 6.0.3 again:\n\n- Inline `NoStrayRuleKeys\u003cR>` as `{ [K in keyof R]: unknown }`. The named alias is needed.\n- Replace `Required\u003cT>` with `T` in the true arm.\n- Make the stray keys non-distributive: `Exclude\u003ckeyof R, keyof T>` instead of `R extends unknown ? … : never`. This also removes the circularity.\n- Drop the stray-key mapped type.\n- Use a literal key that matches a literal-keyed config (`literal.derive`), or a constraint without self-reference (`plain`).\n\nRemoving the `[keyof R] extends [never]` conditional (keeping only `NoStrayRuleKeys\u003cR>`) makes 6.0.3 fail with TS7006 as well. Swapping the intersection order to `StrictRules\u003cR, T> & T` still reproduces.\n\nThe unreduced library nests this one level deeper (`{ [key]: { [key]: (el) => el } }`, a recursive `StrictRules`, and a `RequireAtLeastOne\u003cT>` arm). It fails the same way on 7.x and works on 6.0.3.\n\nPossibly related:\n\n- #64534 has similar ingredients: a circular mapped property inside an intersection, with the contextual type coming from another member's index signature (the #52095 fallback). It was closed because it lacked a concrete case where the behavior is wrong. This issue is such a case: the same circular input type-checks on 6.0.3 and gets TS7006 on 7.x.\n- #64091: dependent contextual inference for `T extends F\u003cT>` (open suggestion).\n- #64974 and #65011: other 7.1 contextual-typing losses (TS7031).\n","author":{"url":"https://github.com/Flarette","@type":"Person","name":"Flarette"},"datePublished":"2026-11-16T16:46:09Z","url":"https://github.com/microsoft/TypeScript/issues/65530"}
| 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:ed37c294-0205-2212-6efc-a32d0a887bff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFA6:2E7EBB:6F0C7F:8E0AD3:6B00E134 |
| html-safe-nonce | c6cbecb2309dcf6afe89e184fae9a29feb02594c2a2034f71ca404c4c58467c1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkE2OjJFN0VCQjo2RjBDN0Y6OEUwQUQzOjZCMDBFMTM0IiwidmlzaXRvcl9pZCI6Ijc0NTk2MzkzMjQ3OTYwNTE3NjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 392a7da38a7f1c45c8a50d916bc46a2d62fb2b67dbab715d8ab802cb21547e43 |
| hovercard-subject-tag | issue:6426082589 |
| 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/65530/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9e5dbb976c1cd4ebe81ffb922d443d9932e417d31dcfa8f8511c8c3f02195f98/microsoft/TypeScript/issues/65530 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9e5dbb976c1cd4ebe81ffb922d443d9932e417d31dcfa8f8511c8c3f02195f98/microsoft/TypeScript/issues/65530 |
| og:image:alt | 🔎 Search Terms TS7006, implicitly has an 'any' type, contextual type, computed property name, string index signature, self-referential constraint, R extends F |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Flarette |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width