```ts
function flatten(items: readonly unknown[], depth = Infinity): unknown[] {
  if (depth < 0) {
    throw new Error('Depth must be non-negative');
  }

  return items.reduce((acc, item) => {
    if (Array.isArray(item)) {
      const nestedItems = flatten(item as unknown[], depth - 1);
      acc.push(...nestedItems);
    } else {
      acc.push(item);
    }
    return acc;
  }, [] as unknown[]);
}
```