UNPKG

typedash

Version:

modern, type-safe collection of utility functions

24 lines (21 loc) 608 B
import { Writable } from 'type-fest'; /** * Inverts the keys and values of an object. * @param object The object to invert. * @returns A new object with the keys and values inverted. * * If the object has duplicate values, the last key will be used. * @example * ```typescript * invert({ * a: 'x', * b: 'y', * c: 'z' * }); // { x: 'a', y: 'b', z: 'c' } * ``` */ declare function invert<const T extends Record<PropertyKey, PropertyKey>>(object: T): Writable<Inverted<T>>; type Inverted<T extends Record<PropertyKey, PropertyKey>> = { [K in keyof T as T[K]]: K; }; export { invert };