Skip to content
AgileLogics
4 min read

Enums

Prerequisites: Literal types

An enum is a named set of related constant values — an alternative to a string-literal union when you want a proper named type with its own identity.

enum Role {
    Member,
    Admin,
    Owner,
}

function isAdmin(role: Role): boolean {
    return role === Role.Admin;
}

isAdmin(Role.Admin); // true

Many teams prefer a string-literal union ("member" | "admin" | "owner") over enum for simple cases, since it needs no extra runtime code and serializes to JSON directly — enums are worth knowing since they appear often in existing codebases.