Skip to content

Instantly share code, notes, and snippets.

@yornaath
Last active July 17, 2019 12:00
Show Gist options
  • Save yornaath/543ca4857ef8fbc6485b2243cf246ca9 to your computer and use it in GitHub Desktop.
Save yornaath/543ca4857ef8fbc6485b2243cf246ca9 to your computer and use it in GitHub Desktop.
export const enum Job {
FOO = "FOO",
BAR = "BAR"
}
export const doJob = (job: Job) => {
if(job == Job.FOO) {
foo()
}
if(job == Job.BAR) {
bar()
}
}
// OR
export type SomeJob = "SOME_JOB";
export type AnotherJob = "ANOTHER_JOB";
export type Job = SomeJob | AnotherJob;
const doJob = (job:Job) => {
if(job == "SOME_JOB") {
...
}
if(job == "ANOTHER_JOB") {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment