Skip to content

assertSetIncludes

Assert that a Set includes a specific member, with type narrowing.

Membership uses the Set’s own has(), which is a SameValueZero match, so an object only fulfills the assertion by being a reference the Set already holds, rather than equivalent in value to a member.

assertSetEquals() compares members by value.

Note that presence has no type-level witness the way an array’s leading tuple slot gives one, so this narrows an unknown value to a Set of the member type and stops there.

import { assertSetIncludes } from "@kensio/smartass";
const value: unknown = new Set(["draft", "featured"]);
assertSetIncludes(value, "draft");
// value is now narrowed to ReadonlySet<"draft">

Source file: src/assert/set-includes/set-includes.assert.ts