```ts
/**
 * Splits a single line of CSV into its fields on commas.
 * A field wrapped in double quotes may contain commas, and a doubled quote inside such a field means one literal quote character;
 * the surrounding quotes are not part of the value. 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.
 */
export function parseCsvLine(line: string): string[] {
    const result: string[] = [];
    let currentField: string | null = null;
    let inQuotes: boolean = false;
    let quoteChar: string | null = null;

    for (const char of line) {
        if (char === '"') {
            if (inQuotes) {
                if (!result.length || result[result.length - 1] !== undefined) {
                    throw new Error("Unfinished quoted field");
                }
            } else {
                inQuotes = true;
                quoteChar = char;
            }
        } else if (char === ',' && currentField !== null && !inQuotes) {
            result.push(currentField);
            currentField = null;
        } else {
            if (currentField === null) {
                currentField += char;
            } else {
                currentField += char;
            }
        }
    }

    if (currentField !== null) {
        return [currentField];
    } else {
        result.push('');
    }

    return result;
}
```