Microsoft/TypeScript
GitHub ã§èŠãNo error on self-referencing type parameter of non-generic mapped type
Open
#62,176 opened on 2025幎8æ2æ¥
BugDomain: Mapped TypesHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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 ð