```ts
function flatten(items: readonly unknown[], depth = Infinity): 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)) {
      const flattenedItem = flatten(item as readonly unknown[], depth - 1);
      acc.push(...flattenedItem);
    } else if (typeof item === 'object' && item !== null) {
      for (const key in item) {
        if (item.hasOwnProperty(key)) {
          acc.push(flatten([item[key]], depth - 1)[0]);
        }
      }
    } else {
      acc.push(item);
    }
    return acc;
  }, []);
}
```