```typescript
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
    if (depth === undefined) depth = Infinity;
    
    // Validate depth
    if (!Number.isInteger(depth) && depth !== Infinity) {
        throw new Error("Depth must be a non-negative integer or Infinity.");
    }
    
    const result: unknown[] = [];
    
    function process(item: unknown, currentDepth = 0): void {
        if (currentDepth > depth || typeof item !== 'object' || item === null) {
            result.push(item);
        } else if (Array.isArray(item)) {
            item.forEach((subItem) => process(subItem, currentDepth + 1));
        }
    }
    
    items.forEach(process);
    
    return result;
}
```