[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/037c390af081e9944d616ff298a729515c5c5ab7/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<NonEmptyReadonlySet<number>, typeof set>();
assertEqual(set.size, 3);
```