ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Set in TypeScript is a generic, iterable collection of unique values. It wraps the native ECMAScript 6 Set object with TypeScript’s static type system, ensuring that all elements within the collection conform to a specified type parameter <T>. Uniqueness is evaluated using the SameValueZero algorithm, meaning NaN is considered equal to NaN, and duplicate values are silently ignored during insertion.
Instantiation and Type Inference
ASet can be instantiated empty with an explicit generic type argument, or initialized with an iterable object (like an Array), from which TypeScript will infer the type.
Core API
TheSet prototype provides a standard set of methods for mutation and inspection.
add(value: T): this: Appends a new element with the specified value. Returns theSetinstance, enabling method chaining.has(value: T): boolean: Evaluates whether an element with the specified value exists within the collection.delete(value: T): boolean: Removes the specified element. Returnstrueif the element existed and was removed, orfalseif it did not exist.clear(): void: Removes all elements from theSet.size: number: A read-only property returning the total count of elements.
Object Reference Equality
When storing complex types (objects, arrays, functions), uniqueness is determined by memory reference, not structural equality. Two structurally identical objects are treated as distinct elements.Iteration
Set objects are natively iterable and maintain insertion order. They can be traversed using for...of loops or the built-in forEach method.
Native Set Operations (TypeScript 5.5+ / ES2024)
Modern TypeScript supports native mathematical set operations, returning newSet instances without mutating the originals.
Master TypeScript with Deep Grasping Methodology!Learn More





