Microsoft/TypeScript
Ver no GitHubNo error on self-referencing type parameter of non-generic mapped type
Open
#62.176 aberto em 2 de ago. de 2025
BugDomain: Mapped TypesHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
🔎 Search Terms
mapped type circular self reference type parameter
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type Test = keyof {
[P in keyof P]: unknown
};
declare const test: Test;
export function getTest() {
return test;
}
🙁 Actual behavior
[P in keyof P] doesn't error anyhow but it's clearly circular. Furthermore, the generated .d.ts here is:
export declare function getTest(): keyof P;
P leaked here and this is invalid
🙂 Expected behavior
I'd expect this to produce a circularity error and at the very least the generated declaration file should not contain a leaked type variable
Additional information about the issue
cc @jfet97 who originally mentioned part of this to me in a DM 😉