Last active
November 14, 2021 10:53
-
-
Save KonstantinBozhkov/ee025676a59c41940acbda5a411ceb22 to your computer and use it in GitHub Desktop.
Typescript inverse key value type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type V = string | symbol | number; | |
export type InverseKeyValue<T extends { [K in V]: V }> = T extends { [K in infer A]: infer B } | |
? B extends V | |
? { [K in B]: A } | |
: never | |
: never; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment