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

  let result = '';
  let lastChar = '';
  let charCount = 0;

  for (const char of input) {
    if (char === lastChar) {
      charCount++;
    } else {
      result += `${lastChar}${charCount}`;
      lastChar = char;
      charCount = 1;
    }
  }

  result += `${lastChar}${charCount}`;
  return result.slice(2); // Remove the leading placeholder
}
```