Skip to main content

mapValues

Callable

  • mapValues<T, Mapper>(obj: T, mapper: Mapper): { [ K in keyof T ]: Mapper extends (v: T[K], k: K) => infer O ? O : never }

  • Returns an object with same keys, where the original values are converted using a mapper.

    Example

    mapValues({ foo: 0, bar: 2 }, (x) => x + 1)
    // => { foo: 1, bar: 3 }

    Alternatives


    Type parameters

    • T: object | ArrayLike<unknown>
    • Mapper: (v: T[keyof T], k: keyof T) => unknown

    Parameters

    • obj: T

      The object to map the values from.

    • mapper: Mapper

    Returns { [ K in keyof T ]: Mapper extends (v: T[K], k: K) => infer O ? O : never }

    The keys as an array.