Microsoft/TypeScript
GitHub ã§èŠãMultiple keys being remapped to same key causes unstable modifier propagation
Open
#62,318 opened on 2025幎8æ22æ¥
BugDomain: Mapped TypesHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
Mapped Types, Key Remapping
ð Version & Regression Information
- This has been happening since first release of key remapping at 4.1 (tested with v4.1.5 at Playground) until nightly (tested with v6.0.0-dev.20250822 at Playground).
⯠Playground Link
ð» Code
type RemapKeyToInitialPart<T> = {
[K in keyof T as K extends `${infer First}.${infer _Rest}` ? First : K]: null;
};
type FirstOptional = RemapKeyToInitialPart<{
// ^?
"foo.bar"?: string;
"foo.baz": number;
}>;
type FirstRequired = RemapKeyToInitialPart<{
// ^?
"foo.baz": number;
"foo.bar"?: string;
}>;
ð Actual behavior
type FirstOptional and type FirstRequired results in different types:
type FirstOptionalhas optional propertyfootype FirstRequiredhas required propertyfoo
ð Expected behavior
type FirstOptional and type FirstRequired results in same type. I would expect it to be same as type FirstRequiredtype FirstOptional.
Additional information about the issue
My motivation was to implement a utility type Expand<T> which transforms { "foo.bar": number } to { foo: { bar: number } } (playground)