Const// Accepts both Set and WeakSet
AnySetSchema.parse(new Set([1, 2, 3])); // ✓ passes
AnySetSchema.parse(new WeakSet([obj1, obj2])); // ✓ passes
AnySetSchema.parse(new Map()); // ✗ fails (wrong collection type)
// Usage in assertions
expect(myWeakSet, 'to contain', someObject); // Works with WeakSet
expect(mySet, 'to contain', 'string'); // Works with Set
Schema that matches either
SetorWeakSetinstances.This unified schema handles both strong and weak Set types, making it useful for assertions that should work with either variant. The distinction between Set and WeakSet is important for garbage collection behavior but often irrelevant for structural assertions.
Key Differences Between Set and WeakSet:
Usage Scenarios:
WeakSet Limitations: