Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 5 of 56 · Typescript

Literal Types & Enums

Duration: 20 minutes

Literal Types

A literal type is the exact value of a primitive.

type YesNo = "yes" | "no";
let answer: YesNo = "yes"; // OK

Numeric Literal Types

type OneToThree = 1 | 2 | 3;
let n: OneToThree = 2;

Enums

Enumerations provide a named set of values.

enum Direction {
  Up = "UP",
  Down = "DOWN",
  Left = "LEFT",
  Right = "RIGHT"
}

let dir: Direction = Direction.Up;

Const enums (inlined at compile time)

const enum Color { Red, Green, Blue }
let c = Color.Green; // emitted as 1

Info

Prefer union of literals over enums unless you need runtime representation.

Previous: Union & Intersection TypesNext: Type Aliases & Interfaces