```ts
/**
 * Splits an array into consecutive groups of at most size elements.
 * The final group is shorter if the length does not divide evenly.
 *
 * @param {readonly T[]} items - The array to split.
 * @param {number} size - The maximum number of elements per chunk. Must be a positive integer.
 * @returns {T[][]} An array of arrays, where each sub-array contains at most `size` elements from the original array.
 */
export function chunk<T>(items: readonly T[], size: number): T[][] {
  if (!Number.isInteger(size) || size <= 0) {
    throw new Error(`Invalid size: ${size}`);
  }

  const result: T[][] = [];
  let start = 0;

  while (start < items.length) {
    const end = Math.min(start + size, items.length);
    result.push(items.slice(start, end));
    start = end;
  }

  return result;
}
```