```ts
export function runLengthEncode(input: string): string {
  if (typeof input !== 'string') {
    throw new Error('The argument must be a string.');
  }

  let result = '';
  let currentChar = input[0];
  let currentCount = 1;

  for (let i = 1; i < input.length; i++) {
    const char = input[i];
    if (char === currentChar) {
      currentCount++;
    } else {
      result += `${currentChar}${currentCount}`;
      currentChar = char;
      currentCount = 1;
    }
  }

  // Add the last run
  result += `${currentChar}${currentCount}`;

  return result;
}
```