```ts
/**
 * Splits an array into consecutive groups of at most size elements.
 * The final group is shorter when the length does not divide evenly.
 *
 * @param items - A readonly array to be chunked.
 * @param size - An integer representing how many elements each chunk should contain.
 * 
 * @returns An array of chunks, where each chunk is an array itself.
 */
export function chunk<T>(items: readonly T[], size: number): T[][] {
  if (size <= 0) {
    throw new Error("Size must be a positive integer");
  }

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

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

  return result;
}
```