Skip to content

Instantly share code, notes, and snippets.

@silvandiepen
Created November 28, 2022 10:55
Show Gist options
  • Save silvandiepen/548deb860be6922ffd674fc35c28ffea to your computer and use it in GitHub Desktop.
Save silvandiepen/548deb860be6922ffd674fc35c28ffea to your computer and use it in GitHub Desktop.
Write better Enums
// Wrong
enum MyEnum {
MT = 'Malta',
NL = 'Nederland',
UK = 'United Kingdom'
}
// Right
const MyEnum = {
MT: 'Malta',
NL: 'Nederland',
UK: 'United Kingdom'
}
type MyEnum = typeof MyEnum[keyof typeof MyEnum];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment