```ts
/**
 * Splits one line of CSV into its fields on commas. Handles quoted fields that may contain commas
 * and escaped quotes within them. Throws an Error for a quoted field that is never closed.
 *
 * @param line - The CSV line to parse.
 * @returns An array of fields.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let currentField = '';
    let inQuotes = false;

    for (let i = 0; i < line.length; i++) {
        const char = line[i];

        if (char === '"') {
            if (inQuotes) {
                // Check for escaped quote
                if (i + 1 < line.length && line[i + 1] === '"') {
                    currentField += char;
                    i++; // Skip the next character as it's part of the field
                } else {
                    inQuotes = false;
                }
            } else {
                inQuotes = true;
            }
        } else if (char === ',' && !inQuotes) {
            result.push(currentField.trim());
            currentField = '';
        } else {
            currentField += char;
        }
    }

    if (inQuotes) {
        throw new Error('Quoted field never closed');
    }

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