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

Defined in: [packages/common/src/RefCount.ts:61](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/RefCount.ts#L61)

Reference counts keyed by logical identity.

By default, [createRefCountByKey](https://evolu.dev/docs/api-reference/common/RefCount/functions/createRefCountByKey) uses reference identity, the same as
`Map` keys. Callers may instead provide a [lookup](https://evolu.dev/docs/api-reference/common/Lookup/type-aliases/Lookup) so logical
equality is based on a derived stable key. Decrementing a missing key is a
programmer error checked with [assert](https://evolu.dev/docs/api-reference/common/Assert/variables/assert).

## Extends

- [`Disposable`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management)

## Methods

<a id="dispose"></a>

### \[dispose\]()

```ts
dispose: void;
```

Defined in: node\_modules/@typescript/old/lib/lib.esnext.disposable.d.ts:34

#### Inherited from

```ts
Disposable.[dispose]
```

## Properties

<a id="decrement"></a>

### decrement

```ts
readonly decrement: (key: TKey) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
```

Defined in: [packages/common/src/RefCount.ts:71](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/RefCount.ts#L71)

Decrements key count and returns the new count.

Decrementing a missing key is a programmer error checked with
[assert](https://evolu.dev/docs/api-reference/common/Assert/variables/assert).

### getCount

```ts
readonly getCount: (key: TKey) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
```

Defined in: [packages/common/src/RefCount.ts:74](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/RefCount.ts#L74)

Gets current count for key. Returns `0` when the key is not tracked.

### has

```ts
readonly has: (key: TKey) => boolean;
```

Defined in: [packages/common/src/RefCount.ts:77](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/RefCount.ts#L77)

Returns `true` when the key is tracked with count greater than zero.

### increment

```ts
readonly increment: (key: TKey) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
```

Defined in: [packages/common/src/RefCount.ts:63](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/RefCount.ts#L63)

Increments key count and returns the new count.

### keys

```ts
readonly keys: () => ReadonlySet<TKey>;
```

Defined in: [packages/common/src/RefCount.ts:80](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/RefCount.ts#L80)

Returns all currently tracked keys.