```ts
function flatten<T>(
  items: readonly T[],
  depth?: number
): unknown[] {
  if (depth === undefined) return [...items];

  const result = [];

  function innerFlatten(item: T, currentDepth = 0) {
    if (Array.isArray(item)) {
      for (const subItem of item) {
        innerFlatten(subItem, currentDepth + 1);
      }
    } else if (typeof item === 'object' && item !== null) {
      const keys = Object.keys(item);
      for (const key of keys) result.push({ [key]: item[key] });
    } else {
      result.push(item);
    }
  }

  innerFlatten(items);

  return result;
}
```