```ts
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 (i > 0 && line[i - 1] === '"' && !inQuotes) {
                // Double quote inside unquoted field
                currentField += char;
            } else {
                inQuotes = !inQuotes;
            }
        } else if (char === ',' && !inQuotes) {
            result.push(currentField.trim());
            currentField = '';
        } else {
            currentField += char;
        }

        if (i === line.length - 1 && inQuotes) {
            throw new Error('Unquoted field is closed with a quote');
        }
    }

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