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

    let result = '';
    let count = 1;

    for (let i = 0; i < input.length; i++) {
        const current = input[i];
        const next = i + 1 < input.length ? input[i + 1] : '';

        if (current === next) {
            count++;
            continue;
        } else {
            result += current.repeat(count);
            count = 1;
        }
    }

    return result;
}
```