Skip to content

Commit

Permalink
Implement stronger mapped TypeScript type (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
artginzburg authored Feb 26, 2022
1 parent 9f03118 commit 4b96de4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ invertKeyValue({foo: 'bar', '🦄': '🌈'});
```
*/
export default function invertKeyValue<
KeyType extends PropertyKey,
ValueType extends PropertyKey
T extends Record<PropertyKey, PropertyKey>
>(
object: {[key in KeyType]: ValueType}
): {[key in ValueType]: KeyType extends number ? Exclude<KeyType, number> | string : KeyType};
object: T
): {[P in keyof T as T[P]]: keyof T extends number ? Exclude<keyof T, number> | string : P};

0 comments on commit 4b96de4

Please sign in to comment.