Here's how you could implement chunk in TypeScript:
 
```ts
/** Split an array into consecutive groups of at most size elements */
export function chunk<T>(items: readonly T[], size: number): T[][] {
  if (!Number.isInteger(size) || size < 1) {
    throw Error('Size must be a positive integer');
  }
  const result = [];
  for (let i = 0; i < items.length; i += size) {
    result.push([...items.slice(i, i + size)]);
  }
  return result;
}
```