```ts
/**
 * Splits an array into consecutive groups of at most the specified size.
 *
 * @param items - The input array to split; will not be mutated.
 * @param size  - The maximum number of elements per group; must be a positive integer.
 * @returns A new array containing subarrays (chunks) of the original items in order.
 */
export function chunk<T>(items: readonly T[], size: number): T[][] {
    if (!Number.isInteger(size) || size <= 0) {
        throw new Error('Size must be a positive integer');
    }

    const chunks: T[][] = [];
    for (let i = 0; i < items.length; i += size) {
        chunks.push(items.slice(i, i + size));
    }
    return chunks;
}
```