Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

boolean

The primitive boolean type represents the two values true and false. In TypeScript, boolean is equivalent to the union true | false; use lowercase boolean rather than boxed Boolean.

How it works

Use the lowercase boolean type for values that are either true or false. TypeScript treats boolean as the union of the two boolean literal types, true and false, while uppercase Boolean refers to a distinct boxed-object type that should generally be avoided.

Syntax

boolean

Key points

  • The lowercase boolean type corresponds to JavaScript's primitive boolean value.
  • A boolean annotation permits exactly true or false.
  • TypeScript provides true and false as narrower boolean literal types.
  • boolean is equivalent to the union of both boolean literal types.

Common mistakes

  • Do not substitute uppercase Boolean for the primitive boolean type; it denotes a different built-in object type.

Example: Using boolean flags

type FeatureFlags = {
  darkMode: boolean;
  betaSearch: boolean;
};

const flags: FeatureFlags = {
  darkMode: true,
  betaSearch: false,
};

if (flags.darkMode) {
  console.log("dark mode enabled");
}

The object uses the primitive boolean type, whose value can be true or false.

When to use it

Feature flags

Modeling enabled or disabled configuration options.

Binary state

Representing the outcome of a yes-or-no validation or permission check.

Typed result variants

Discriminating union members with true and false literal properties.

Interview questions

QWhat values does boolean represent?

The primitive boolean type represents exactly two values: true and false. TypeScript models it as the union true | false.

Follow-up: How would you require a property to be permanently true? Use the boolean literal type true rather than boolean.

QWhy should Boolean usually be avoided?

Use lowercase boolean in annotations. Uppercase Boolean is legal but refers to a special boxed built-in type and is rarely appropriate in application code.

Follow-up: What analogous naming rule applies to other primitives? Prefer string and number over String and Number.

QWhen are boolean literal types useful?

Boolean literals are the types true and false. They are useful when discriminating related object shapes, because a literal property can select a particular union member.

Follow-up: How can a boolean discriminant relate fields? Define separate union members with isValid: true and isValid: false, giving each member different accompanying properties.

  • true
  • false
  • string
  • number
  • Boolean
  • Literal Types
  • Everyday Types

Source: Documentation - Everyday Types - TypeScript. Checked 2026-10-15.