```typescript
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
  if (typeof depth !== 'number' || depth < 0 && depth !== Infinity) {
    throw new Error('Depth must be a non-negative integer or Infinity');
  }

  return items.flat(depth);
}
```