```ts
/**
 * Flattens an array up to a specified depth level.
 * @param items The array to flatten.
 * @param depth The recursion depth limit (default is Infinity).
 * @returns A new flattened copy of the input array.
 */
export function flatten(items: readonly unknown[], depth?: number): unknown[] {
  if (typeof items !== 'object' || items === null || Array.isArray(items)) return [...items];
  if (depth === undefined || depth < 0) return [...items];

  let result: unknown[] = [];
  for (const item of items as any[]) {
    if (Array.isArray(item)) {
      const subFlattened = flatten(item, depth - 1);
      result.push(...subFlattened);
    } else {
      result.push(item);
    }
  }

  return result;
}
```