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

    const result: unknown[] = [];

    const dfs = (currentItems: readonly unknown[], currentDepth: number) => {
        for (const item of currentItems) {
            if (Array.isArray(item) && (depth === undefined || currentDepth < depth)) {
                dfs(item, currentDepth + 1);
            } else if (typeof item !== 'string') {
                result.push(item);
            }
        }
    };

    dfs(items, 0);
    return result;
}
```