this post was submitted on 14 Aug 2025
274 points (96.3% liked)
Programmer Humor
25705 readers
1392 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
My preferred way of modelling this would probably be something like
role: "admin" | "regular" | "logged-out"
or
type Role = "admin" | "regular";
role: Role | null
depending on whether being logged out is a state on the same level as being a logged-in (non-)admin. In a language like Rust,
enum Role {Admin, Regular}
instead of just using strings.
I wouldn't consider performance here unless it clearly mattered, certainly not enough to use
role: number
,which is just about the least type-safe solution possible. Perhaps
role: typeof ADMIN | typeof REGULAR | typeof LOGGED_OUT
with appropriately defined constants might be okay, though.
Disclaimer: neither a professional programmer nor someone who regularly writes TypeScript as of now.