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

  return items.reduce((acc, item) => {
    if (Array.isArray(item)) {
      acc.push(...flatten(item, depth - 1));
    } else if (typeof item === 'object' && item !== null) {
      acc.push(...Object.values(item));
    } else {
      acc.push(item);
    }
    return acc;
  }, []);
}
```