```ts
/**
 * Splits a line of CSV into its fields on commas, handling quoted fields with embedded commas and doubled quotes.
 * @param line - The CSV line to split.
 * @returns An array of string fields.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let field = '';
    let inQuotes = false;

    for (let i = 0; i < line.length; i++) {
        if (line[i] === '"') {
            if (i > 0 && line[i - 1] === '"') {
                field += '"';
                i++; // Skip the next character as it's part of the quote
            } else {
                inQuotes = !inQuotes;
            }
        } else if (line[i] === ',' && !inQuotes) {
            result.push(field.trim());
            field = '';
        } else {
            field += line[i];
        }
    }

    if (inQuotes) {
        throw new Error('Unquoted quote found');
    }

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