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

  if (typeof depth !== 'number' || depth < 0 || (!Number.isInteger(depth) && depth !== Infinity)) {
    throw new Error('Depth must be a non-negative integer or Infinity');
  }

  const result: unknown[] = [];

  function flattenImpl(items: readonly unknown[], currentDepth: number): void {
    for (const item of items) {
      if (Array.isArray(item) && currentDepth > 0) {
        flattenImpl(item, currentDepth - 1);
      } else if (typeof item !== 'string') {
        result.push(item);
      }
    }
  }

  flattenImpl(items, depth);

  return result;
}
```