```ts
/**
 * Encodes a string using run-length encoding.
 * @param input - The string to encode.
 * @returns The encoded string with each character followed by its count.
 * @throws Error if the input is not a string.
 */
export function runLengthEncode(input: string): string {
  if (typeof input !== 'string') {
    throw new Error('Input must be a string');
  }

  let result = '';
  let currentChar = '';
  let count = 0;

  for (const char of input) {
    if (char === currentChar) {
      count++;
    } else {
      if (currentChar !== '') {
        result += `${currentChar}${count}`;
      }
      currentChar = char;
      count = 1;
    }
  }

  // Append the last run
  if (currentChar !== '') {
    result += `${currentChar}${count}`;
  }

  return result;
}
```