```ts
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');
  }

  const result = [];

  for (const item of items) {
    if (Array.isArray(item)) {
      result.push(...flatten(item, depth - 1));
    } else if (item !== null && item !== undefined && typeof item === 'object') {
      // For objects, we assume they are nested and will be handled recursively
      result.push(...flatten(Object.values(item), depth - 1));
    } else {
      result.push(item);
    }
  }

  return result;
}
```