```ts
/**
 * Splits one line of CSV into its fields on commas.
 * Handles quoted fields that may contain commas and doubled quotes inside.
 * Throws an Error for a quoted field that is never closed.
 *
 * @param line - A string representing a single line of CSV data.
 * @returns An array of strings representing the fields in the line.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let currentField = '';
    let inQuotes = false;

    for (const char of line) {
        if (char === '"') {
            if (inQuotes && currentField.endsWith('"')) {
                // Remove the trailing quote
                currentField = currentField.slice(0, -1);
                inQuotes = false;
            } else if (!inQuotes) {
                inQuotes = true;
            }
        } else if (char === ',' && !inQuotes) {
            result.push(currentField.trim());
            currentField = '';
        } else {
            currentField += char;
        }
    }

    if (inQuotes) {
        throw new Error('Unquoted double quote at end of line');
    }

    result.push(currentField.trim());
    return result;
}
```