```ts
export function runLengthEncode(input: string): string {
    /**
     * Encodes every maximal run of one repeated character in `input` into a sequence of that character followed by its count.
     */

    if (typeof input !== 'string') {
        throw new Error('Input must be a string');
    }

    const result = [];
    let currentChar = '';
    let currentCount = 0;

    for (const char of input) {
        if (char === currentChar) {
            currentCount += 1;
        } else {
            if (currentChar) {
                result.push(currentChar + (currentCount > 0 ? currentCount : ''));
            }
            currentChar = char;
            currentCount = 1;
        }
    }

    result.push(currentChar + (currentCount > 0 ? currentCount : ''));

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