```ts
/**
 * Split an array into consecutive groups of at most size elements.
 * @param items - The array to chunk.
 * @param size - The maximum number of elements in each group. must be a positive integer.
 */
export function chunk<T>(items: readonly T[], size: number): T[][] {
  if(!Array.isArray(items)) {
    throw new Error(`Expected an array, got:${typeof items}`);
  }
  if(typeof size !== 'number' || typeof size === 'string') {
    throw new Error('Size must be a valid positive integer');
  }
  
  if(size <= 0) {
    throw new Error('Size cannot be less than or equal to zero');
  }

  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;
}
```