index.d.ts 635 B

123456789101112131415161718192021
  1. // TODO: Extend this to symbol when TS allows symbols in index signatures:
  2. // https://github.com/Microsoft/TypeScript/issues/1863
  3. /**
  4. Invert the key/value of an object. Example: `{foo: 'bar'}` → `{bar: 'foo'}`.
  5. @example
  6. ```
  7. import invertKeyValue = require('invert-kv');
  8. invertKeyValue({foo: 'bar', '🦄': '🌈'});
  9. //=> {bar: 'foo', '🌈': '🦄'}
  10. ```
  11. */
  12. declare function invertKeyValue<
  13. KeyType extends string | number,
  14. ValueType extends string | number | symbol
  15. >(
  16. object: {[key in KeyType]: ValueType}
  17. ): {[key in ValueType]: KeyType extends number ? Exclude<KeyType, number> | string : KeyType};
  18. export = invertKeyValue;