```ts
/**
 * Parses a single line of CSV into its fields.
 * @param line - The CSV line to parse.
 * @returns An array of strings representing the 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 (i + 1 < line.length && line[i + 1] === '"') {
                // Double quote inside a quoted field
                currentField += '"';
                i++; // Skip the next character as it's part of the escape sequence
            } else {
                // Toggle quotes
                inQuotes = !inQuotes;
            }
        } else if (char === ',' && !inQuotes) {
            // End of a field
            result.push(currentField);
            currentField = '';
        } else {
            // Add character to the current field
            currentField += char;
        }
    }

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

    // Push the last field if there's any content
    if (currentField !== '' || line.endsWith(',')) {
        result.push(currentField);
    }

    return result;
}
```