```typescript
export function chunk<T>(items: readonly T[], size: number = 1): T[][] {
    // Error check for invalid size
    if (size <= 0) {
        throw new Error("Size must be a positive integer.");
    }

    // Using map to collect groups
    return items.map((_, index) => {
        const groupIndex = Math.floor(index / size);
        if (!Array.isArray(groups[groupIndex])) {
            groups[groupIndex] = [];
        }
        groups[groupIndex].push(items[index]);
        return groups;
    }, []).reduce((acc, groupsAtIndex) => [...acc, groupsAtIndex], [] as T[][]);
}
```