TypeScript Types

symbol — symbol primitive

The symbol type accepts JavaScript symbol values. A fresh Symbol() call creates a distinct identity even when its description matches another symbol. Symbols can serve as object keys; they are not strings. The broad symbol type does not preserve the identity of one particular declared symbol; use unique symbol where that matters. Example output: "7". The example was designed for strict checking with an ES2022 target; type annotations do not add runtime validation.

Formal Syntax & Structure

typescript syntaxtypescript
let key: symbol;

Working Example

Example Snippettypescript
const key: symbol = Symbol("record");const record = { [key]: 7 };console.log(record[key]);
TypeScript Reference