UNPKG

419 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 KeyType extends PropertyKey,
14 ValueType extends PropertyKey
15>(
16 object: {[key in KeyType]: ValueType}
17): {[key in ValueType]: KeyType extends number ? Exclude<KeyType, number> | string : KeyType};