```ts
import { assert } from 'assert';

export function flatten<T>(items: readonly T[], depth?: number): unknown[] {
  if (typeof depth !== 'number' || depth < 0) {
    throw new Error('depth must be a non-negative integer or Infinity');
  }

  return items.reduce((acc, item) => {
    if (!Array.isArray(item)) {
      acc.push(item);
    } else if (depth > 1) {
      acc.push(...flatten(item, depth - 1));
    }
    return acc;
  }, []);
}

// Check function to verify the correctness of the solution
function checkFlatten() {
  assert.deepEqual(flatten([]), [], 'Empty array');
  assert.deepEqual(flatten(['a', ['b', 'c']]), ['a', 'b', 'c'], 'Single element array');
  assert.deepEqual(flatten([1, [2, 3], 4]), [1, 2, 3, 4], 'Multiple elements array');
  assert.deepEqual(flatten([[5], [[6]]]], [5, 6], 'Nested arrays');
  assert.deepEqual(flatten(['a', ['b', 'c'], 'd'], 0), ['a', ['b', 'c'], 'd'], 'Depth 0');
  assert.deepEqual(flatten([1, [2, [3, [4]]]], 1), [1, 2, [3, [4]]], 'Depth 1');
  try {
    flatten([[]], -1);
  } catch (error) {
    assert(error.message === 'depth must be a non-negative integer or Infinity', 'Invalid depth');
  }
}

checkFlatten();
```