```ts
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
  if (depth === undefined) depth = Infinity;

  const result: unknown[] = [];

  for (const item of items) {
    if (Array.isArray(item)) {
      if (depth > 1) {
        result.push(...flatten(item, depth - 1));
      } else {
        result.push(...item);
      }
    } else if (item !== null && item !== undefined && typeof item === 'object') {
      throw new Error('Flatten cannot flatten objects');
    } else {
      result.push(item);
    }
  }

  return result;
}
```