🔎 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
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAShC2BDMBpCIAqB7AkgOwEtgDEAbABUQCdgAeDAPigF4oBvAKCm6gG0UoBPFADW6LADMoGKIgDOUARAAewCHgAmCgAYASNkIkQqUAGIEqc4AF8AdPsPGoAfThXr2qAH4zFq1AAuRQBdILwAV1JSAG4Oa1iOUEhfS2AAeTBiLDwyFlgEZDRMXEJiMkoaWk4eKAB6WqgAPS8uHgAiCSwsWwAjajavIKsqIQBzWJqOrt7EAC82sPD4HuNY6wYEpOhzVLgAR3CLCA08uCRUdGx8IhIKajpqnnqmlsnO7r75xeXV1u4pj79QZQYZjNYbDhAA
💻 Code
typeRemapKeyToInitialPart<T>={[KinkeyofTasKextends `${infer First}.${infer _Rest}` ? First : K]: null;};typeFirstOptional=RemapKeyToInitialPart<{// ^?"foo.bar"?: string;"foo.baz": number;}>;typeFirstRequired=RemapKeyToInitialPart<{// ^?"foo.baz": number;"foo.bar"?: string;}>;🙁 Actual behavior
type FirstOptional and type FirstRequired results in different types:
type FirstOptional has optional property footype FirstRequired has required property foo
🙂 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)
🔎 Search Terms
Mapped Types, Key Remapping
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAShC2BDMBpCIAqB7AkgOwEtgDEAbABUQCdgAeDAPigF4oBvAKCm6gG0UoBPFADW6LADMoGKIgDOUARAAewCHgAmCgAYASNkIkQqUAGIEqc4AF8AdPsPGoAfThXr2qAH4zFq1AAuRQBdILwAV1JSAG4Oa1iOUEhfS2AAeTBiLDwyFlgEZDRMXEJiMkoaWk4eKAB6WqgAPS8uHgAiCSwsWwAjajavIKsqIQBzWJqOrt7EAC82sPD4HuNY6wYEpOhzVLgAR3CLCA08uCRUdGx8IhIKajpqnnqmlsnO7r75xeXV1u4pj79QZQYZjNYbDhAA
💻 Code
🙁 Actual behavior
type FirstOptionalandtype FirstRequiredresults in different types:type FirstOptionalhas optional propertyfootype FirstRequiredhas required propertyfoo🙂 Expected behavior
type FirstOptionalandtype FirstRequiredresults in same type. I would expect it to be same astype 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)