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

```ts
type RefinementWithIndex<A, B> = (a: A, index: number) => a is B;
```

Defined in: [packages/common/src/Types.ts:174](https://github.com/evoluhq/evolu/blob/bbc8ea18c5844d84d26b2059bd1ba08f5be3d506/packages/common/src/Types.ts#L174)

A type guard function that refines type `A` to a narrower type `B` at a given
index.

Useful for callbacks that need both the element and its position while
maintaining type narrowing.

### Indexed refinement

```ts
import {
  assertTrue,
  assertType,
  partitionArray,
  type RefinementWithIndex,
} from "@evolu/common";

type Item = {
  readonly type: "number" | "string";
  readonly value: unknown;
};
type NumberItem = Item & { readonly type: "number" };

const isNumberItem: RefinementWithIndex<Item, NumberItem> = (
  item,
  index,
): item is NumberItem => index > 0 && item.type === "number";
const items: ReadonlyArray<Item> = [
  { type: "number", value: 1 },
  { type: "number", value: 2 },
];
const [numbers, others] = partitionArray(items, isNumberItem);

assertType<ReadonlyArray<NumberItem>, typeof numbers>();
assertTrue(numbers[0]?.value === 2);
assertTrue(others[0]?.value === 1);
```