Private-like property keys
Create collision-resistant keys for object properties.
TypeScript · Type Alias
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.
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.
let value: symbol = Symbol(description);symbol is a JavaScript primitive type alongside types such as number and string.Symbol(), optionally passing a description.unique symbol for types that represent a particular symbol literal.symbol type does not retain the identity of one particular symbol; use unique symbol when that distinction matters.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.
Create collision-resistant keys for object properties.
Define computed properties whose keys are symbols.
Represent symbol values without preserving one exact identity.
Model a particular exported symbol constant.
unique symbolSymbolcomputed property declarations