```ts
function chunk<T>(items: readonly T[], size: number): T[][] {
  if (size <= 0) {
    throw new Error('Size must be a positive integer');
  }

  return items.reduce((acc, value, index) => {
    const groupId = Math.floor(index / size);
    acc[groupId] ||= []; // Safely get or create an array for the group
    acc[groupId].push(value); // Append the value to the group
    return acc; // Return the accumulator
  }, []);
}
```