TypeScript · Types and shapes

enums

Named constants. Prefer union literals for new code because enums add runtime objects.

Syntax
enum Role { Admin, Learner }

Example

Example
enum Role {
  Admin = "admin",
  Learner = "learner",
}
const role: Role = Role.Admin;

More in this group

any Array types Function type Interface Literal type never null and undefined Optional property

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course