```ts
function runLengthEncode(input: string): string {
  if (typeof input !== 'string') {
    throw Error('Input must be a string');
  }
  let output = '';
  for (let i = 0; i < input.length; i++) {
    const count = 1;
    while (i + count <= input.length && input[i] === input[i + count - 1]) {
      count++;
    }
    output += `${input[i]}${count}`;
  }
  return output;
}
```