```ts
export function flatten(items: readonly unknown[], depth?: number): unknown[]
  throws Error {
    if (depth === undefined) depth = Infinity;
    if (!Number.isInteger(depth)) throw new Error('Non-integer value for depth');
    const result: unknown[] = [];
    for (const item of items) {
      if (typeof item === 'string') result.push(item);
      else if (Array.isArray(item) && depth > 0) {
        result.push(...flatten(item, depth - 1));
      }
    }
    return result;
}
```