```typescript
export function runLengthEncode(input: string): string {
  /**
   * Compresses a string by replacing maximal runs of one repeated character with that character followed by its length:
   * "aaabbc" -> "a3b2c1", "abc" -> "a1b1c1". The empty string remains unaltered.
   * Throws an Error if input is not a string.
   */
  if (typeof input !== 'string') throw new Error('Input must be a string');

  const encoded = [];
  let count = 1;
  for (let i = 1; i <= input.length; i++) {
    if (i < input.length && input[i] !== input[i - 1]) {
          if (count === 1) {
            encoded.push(input[i - 1]);
          } else {
            encoded.push(`${input[i - 1]},${count}`);
          }
          count = 1;
        } else {
          count++;
        }
      }

    // Handle the last character
    if (count === 1 && input.length > i) {
      encoded.push(input[i - 1]);
    } else if (count != 1 && count !== null) {
      encoded.push(`${input[i - 1]},${count}`);
    }

  return encoded.join('');
}
```