Skip to content

Instantly share code, notes, and snippets.

@mtford90
Last active April 22, 2020 17:46
Show Gist options
  • Save mtford90/0cde392e7b71c6fe363ca48b126bc849 to your computer and use it in GitHub Desktop.
Save mtford90/0cde392e7b71c6fe363ca48b126bc849 to your computer and use it in GitHub Desktop.
enum MyEnum {
/* ... */
}
function stringToEnum(str: string): MyEnum | undefined {
return new Map(Object.entries(MyEnum)).get(str)
}
@mtford90
Copy link
Author

Probably a good idea to memoise the Map also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment