Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jasonraimondi/e39dc01e520bc03770e05ab2eb702fe8 to your computer and use it in GitHub Desktop.
Save jasonraimondi/e39dc01e520bc03770e05ab2eb702fe8 to your computer and use it in GitHub Desktop.
enums alternative.ts
const LOG_LEVEL = {
DEBUG: 'DEBUG',
WARNING: 'WARNING',
ERROR: 'ERROR'
} as const;
type ObjectValues<T> = T[keyof T];
type LogLevel = ObjectValues<typeof LOG_LEVEL>
function Log(message: string, level: LogLevel) {}
type LogLevel = keyof typeof LOG_LEVEL
function log(message: string, level: LogLevel) {
console.log('$(LOG_LEVEL [Level]): ${message}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment