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.
WeakSet is a built-in collection that stores unique, weakly held object references. Unlike a standard Set, a WeakSet does not prevent its constituent objects from being reclaimed by the garbage collector if no other strong references to those objects exist in memory.
In TypeScript, WeakSet is defined with a generic type parameter T that is strictly constrained to object (and symbol in ES2023+).
Core Characteristics
1. Object-Only Values Primitives (string, number, boolean, null, undefined) are strictly prohibited. Attempting to add a primitive will result in a TypeScript compiler error.
WeakSet are ephemeral. If the JavaScript engine’s garbage collector destroys an object because it is no longer referenced anywhere else in the application, that object is implicitly and automatically removed from the WeakSet.
3. Non-Iterability
Because garbage collection is non-deterministic, the exact contents of a WeakSet cannot be known or safely enumerated at any given moment. Consequently, WeakSet does not implement the Iterable interface.
- It lacks iteration methods (
forEach,keys,values,entries). - It cannot be used in
for...ofloops. - It does not possess a
sizeproperty. - It cannot be cleared entirely (no
clear()method).
Syntax and API Visualization
AWeakSet exposes only three methods for interacting with its contents: add, has, and delete.
Master TypeScript with Deep Grasping Methodology!Learn More





