JS Built-ins
TypeScriptintermediate

Utility Types β€” mapKeys

πŸ“– Usage Example
mapKeys({ firstName: 'Alice' }, k => k.toLowerCase())
// β†’ { firstname: 'Alice' }

mapKeys transforms each key in an object using a mapping function, preserving the values.

Utility Types: mapKeys

Challenge: Implement mapKeys<T>(obj: Record<string, T>, fn: (k: string) => string): Record<string, T> transforming every key while keeping values.

mapKeys({ a: 1, b: 2 }, k => k.toUpperCase())  // β†’ { A: 1, B: 2 }
πŸ’‘ Hints (1)
  • β€’ Iterate keys, transform each via fn, assign the value to the new key.