```ts
export function chunk<T>(items: readonly T[], size: number): (T[])[];

/**
 * 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.
 * @param size - The maximum size of each chunk.
 * @returns An array of chunks, where each chunk is a subset of `items`.
 */
function chunkImpl(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) {
    result.push(items.slice(i, Math.min(i + size, items.length)));
  }
  return result;
}

export function chunk<T>(items: readonly T[], size: number): (T[])[] {
  /**
   * @see chunkImpl
   */
}
```