Function mapKeys

  • Map the keys of an object using a mapping function

    Returns

    obj with its keys mapped using mapFn

    Example

    const capitalNames = mapKeys({ john: 10, alice: 20 }, k => k.toUpperCase())
    capitalNames === { JOHN: 10, ALICE: 20 }

    Type Parameters

    • TMapped extends PropertyKey

    • TObj extends Record<PropertyKey, any>

    Parameters

    • obj: TObj

      the object to map the keys of

    • mapFn: ((t) => TMapped)

      the mapping function

        • (t): TMapped
        • Parameters

          • t: keyof TObj

          Returns TMapped

    Returns {
        [k in string | number | symbol as TMapped]: TObj[k]
    }

Generated using TypeDoc