UNPKG

372 BTypeScriptView Raw
1/**
2Invert the key/value of an object.
3
4@example
5```
6import invertKeyValue from 'invert-kv';
7
8invertKeyValue({foo: 'bar', '🦄': '🌈'});
9//=> {bar: 'foo', '🌈': '🦄'}
10```
11*/
12export default function invertKeyValue<
13 T extends Record<PropertyKey, PropertyKey>
14>(
15 object: T
16): {[P in keyof T as T[P]]: keyof T extends number ? Exclude<keyof T, number> | string : P};