[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Set](https://evolu.dev/docs/api-reference/common/Set) › isNonEmptySet

```ts
function isNonEmptySet<T>(set: ReadonlySet<T>): set is NonEmptyReadonlySet<T>;
```

Defined in: [packages/common/src/Set.ts:133](https://github.com/evoluhq/evolu/blob/dd96d79f1dbe9a49fa12ce8e0aa7d3d0177795ca/packages/common/src/Set.ts#L133)

Checks if a set is non-empty and narrows its type to
[NonEmptyReadonlySet](https://evolu.dev/docs/api-reference/common/Set/type-aliases/NonEmptyReadonlySet).

Both mutable and readonly sets narrow to the branded
[NonEmptyReadonlySet](https://evolu.dev/docs/api-reference/common/Set/type-aliases/NonEmptyReadonlySet) type, which can be used with functions like
[firstInSet](https://evolu.dev/docs/api-reference/common/Set/functions/firstInSet).

To check if a set is empty, use `if (!isNonEmptySet(set))` — using the
negated guard is better than `.size === 0` for early returns because
TypeScript narrows the type after the check.

### Narrowing before access

```ts
import {
  assertEqual,
  assertType,
  isNonEmptySet,
  type NonEmptyReadonlySet,
} from "@evolu/common";

const set: ReadonlySet<number> = new Set([1, 2, 3]);
if (!isNonEmptySet(set)) throw new Error("Expected a non-empty set");

assertType<typeof set, NonEmptyReadonlySet<number>>();
assertEqual(set.size, 3);
```