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

    let encoded = '';
    let currentChar = '';
    let count = 0;

    for (let i = 0; i < input.length; i++) {
        const char = input[i];
        if (char === currentChar) {
            count++;
        } else {
            if (currentChar !== '') {
                encoded += `${currentChar}${count}`;
            }
            currentChar = char;
            count = 1;
        }
    }

    if (currentChar !== '') {
        encoded += `${currentChar}${count}`;
    }

    return encoded;
}
```