```ts
/**
 * Parses a single line of CSV into its fields on commas. Handles quoted fields
 * with embedded commas and doubled quotes inside them. Fields that are not
 * quoted are taken literally, including any surrounding spaces. An empty line is
 * one empty field. Throws an Error for a quoted field that is never closed.
 *
 * @param line - A single line of CSV to parse.
 * @returns An array of fields extracted from the CSV line.
 */
export function parseCsvLine(line: string): string[] {
    if (!line) return [""];

    const result: string[] = [];
    let field = "";
    let inQuotes = false;
    for (let i = 0; i < line.length; i++) {
        const char = line[i];
        if (char === '"') {
            if (inQuotes && i + 1 < line.length && line[i + 1] === '"') {
                field += char;
                i++; // skip the next double quote
            } else {
                inQuotes = !inQuotes;
            }
        } else if (char === "," && !inQuotes) {
            result.push(field.trim());
            field = "";
        } else {
            field += char;
        }
    }

    if (inQuotes) throw new Error("Unmatched quote in CSV line");

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