```ts
/**
 * Splits one line of CSV into its fields on commas.
 *
 * A field wrapped in double quotes may contain commas, and a doubled quote inside such a field means one literal quote character;
 * the surrounding quotes are not part of the value. Fields that are not quoted are taken literally, including any surrounding spaces.
 * An empty line is one empty field.
 *
 * Throws an Error for a quoted field that is never closed.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let currentField = '';
    let inQuote = false;

    for (const char of line) {
        if (char === '"') {
            inQuote = !inQuote;
            currentField += char;
        } else if (!inQuote && char === ',') {
            if (currentField !== '') {
                result.push(currentField);
                currentField = '';
            }
        } else {
            currentField += char;
        }
    }

    if (currentField !== '') {
        result.push(currentField);
    }

    if (result.some(field => field.startsWith('"'))) {
        const quotedFields: string[] = [];
        for (const field of result) {
            if (field.startsWith('"')) {
                let quoteCount = 0;
                for (let i = 1; i < field.length - 1; i++) {
                    if (field[i] === '"') {
                        quoteCount++;
                    }
                }
                if (quoteCount % 2 !== 0) {
                    throw new Error(`Unbalanced quotes in quoted field: ${field}`);
                }
                const value = field.substring(1, field.length - 1);
                quotedFields.push(value);
            } else {
                quotedFields.push(field);
            }
        }
        result = quotedFields;
    }

    return result;
}
```