```typescript
/**
 * Splits an array into consecutive groups of at most size elements,
 * preserving order; the final group is shorter when the length does not divide evenly.
 *
 * @param items - The input array to be chunked.
 * @param size - The maximum size of each chunk.
 */
export function chunk<T>(items: readonly T[], size: number): T[][] {
    if (typeof size !== 'number' || size <= 0) {
        throw new Error('Size must be a positive integer');
    }

    const result: T[][] = [];

    for (let i = 0; i < items.length; i += size) {
        const chunk = items.slice(i, i + size);
        if (chunk.length > 0) {
            result.push(chunk);
        }
    }

    return result;
}
```