```ts
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
  // Validate depth parameter
  if (typeof depth !== 'number' || !Number.isInteger(depth) && depth !== Infinity) {
    throw new Error('Depth must be a non-negative integer or Infinity');
  }

  const flattened: unknown[] = [];
  for (const item of items) {
    if (Array.isArray(item)) {
      if (depth === 0) {
        flattened.push(...item);
      } else {
        flatten(item, depth - 1).forEach(flatItem => flattened.push(flatItem));
      }
    } else {
      flattened.push(item);
    }
  }

  return flattened;
}
```