```ts
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
  if (depth !== undefined && !(Number.isInteger(depth) && depth >= 0 || depth === Infinity)) {
    throw new Error('Depth must be a non-negative integer or Infinity');
  }

  const result: unknown[] = [];
  const stack: [unknown[], number][] = [[items, depth ?? Infinity]];

  while (stack.length > 0) {
    const [currentItems, currentDepth] = stack.pop()!;
    for (let i = currentItems.length - 1; i >= 0; i--) {
      const item = currentItems[i];
      if (Array.isArray(item) && currentDepth > 0) {
        stack.push([item, currentDepth - 1]);
      } else if (typeof item !== 'string') {
        result.push(item);
      }
    }
  }

  return result.reverse();
}
```