Created
March 13, 2023 19:40
-
-
Save jasonraimondi/e39dc01e520bc03770e05ab2eb702fe8 to your computer and use it in GitHub Desktop.
enums alternative.ts
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
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