```typescript
/**
 * Splits a CSV line into its fields on commas. Handles quotes that may contain commas and escaped double quotes.
 * @param line - The CSV line to split.
 * @returns An array of string fields from the CSV line.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let fieldStart = 0;
    let inQuote = false;

    for (let i = 0; i <= line.length; i++) {
        if (i === line.length || (line[i] === ',' && !inQuote)) {
            const field = line.slice(fieldStart, i).trim();
            if (inQuote) {
                if (!field.includes('""')) throw new Error('Quoted field is never closed');
                result.push(field.replace(/""/g, '"'));
            } else {
                result.push(field);
            }
            inQuote = false;
            fieldStart = i + 1;
        } else if (line[i] === '"') {
            if (inQuote) {
                if (!(i > 0 && line[i - 1] === '"')) throw new Error('Invalid escape sequence');
                inQuote = false;
            } else {
                if (fieldStart < i || (i + 1 < line.length && line[i + 1] === '"'))
                    throw new Error('Quotes must be non-empty and escaped with another quote');
                inQuote = true;
            }
        }
    }

    return result;
}
```