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

TypeScript · Type Alias

symbol

symbol is a primitive type for immutable, unique values created with Symbol(). It can be used for object-property keys, while unique symbol preserves the identity of a specific symbol.

Since
ECMAScript 2015

How it works

The symbol type represents primitive values created with Symbol(). Symbols are immutable and unique, so they can safely serve as object-property keys; use unique symbol when the type system must preserve one specific symbol identity.

Syntax

let value: symbol = Symbol(description);

Key points

  • symbol is a JavaScript primitive type alongside types such as number and string.
  • Create symbol values by calling Symbol(), optionally passing a description.
  • Each symbol is immutable and uniquely identifiable.
  • Symbols are suitable for computed object-property keys.
  • Computed symbol properties work in object and class declarations.
  • Use unique symbol for types that represent a particular symbol literal.

Common mistakes

  • Two symbols created with the same description are still different values; do not compare them as equal.
  • A symbol key is accessed with bracket notation, not dot notation.
  • The broader symbol type does not retain the identity of one particular symbol; use unique symbol when that distinction matters.

Example: Using symbol as an object key

const id: symbol = Symbol("id");
const record = { [id]: "value" };
console.log(record[id]);

This creates a symbol value, uses it as a computed property key, and reads the corresponding property.

When to use it

Private-like property keys

Create collision-resistant keys for object properties.

Computed object members

Define computed properties whose keys are symbols.

General symbol annotations

Represent symbol values without preserving one exact identity.

Unique symbol identities

Model a particular exported symbol constant.

  • unique symbol
  • Symbol
  • computed property declarations

Source: Symbols. Checked 2026-10-15.