```ts
function flatten(items: readonly unknown[], depth = Infinity): unknown[] {
  if (depth < 0) {
    throw new Error('Invalid depth');
  }

  const flattened = [];

  function helper(item: unknown, currentDepth = 1) {
    if (Array.isArray(item)) {
      if (currentDepth === depth || item.length === 1 && !item.every(item => typeof item !== 'object' || !(item as any).flat)) {
        flattened.push(...item);
      } else {
        item.forEach(value => helper(value, currentDepth + 1));
      }
    } else if (typeof item === 'object' && item !== null) {
      const properties = Object.keys(item as {}).reduce((acc, key) => {
        acc[key] = flatten((item as any)[key], depth);
        return acc;
      }, {});
      flattened.push(properties);
    } else {
      flattened.push(item);
    }
  }

  for (const item of items) {
    helper(item);
  }

  return flattened;
}
```