Const// Matches any Set regardless of element types
SetSchema.parse(new Set([1, 2, 3])); // ✓ passes
SetSchema.parse(new Set(['a', 'b'])); // ✓ passes
SetSchema.parse(new Set()); // ✓ passes (empty Set)
SetSchema.parse([]); // ✗ fails (not a Set)
SetSchema.parse(new WeakSet()); // ✗ fails (use AnySetSchema)
Schema that matches any
Setinstance, including those with any element types.This schema is designed for runtime type checking and assertion matching rather than parsing or validation of Set contents. It uses
instanceofchecking to verify that a value is a Set, regardless of what elements it contains.Usage in Assertions:
expect(mySet, 'to have size', 3)expect(setA, 'to be a subset of', setB)expect(mySet, 'to be empty')expect(mySet, 'to contain', value)Why
instanceofInstead of Zod'sz.set():z.set()requires knowing the element schema at compile time