```ts
/**
 * Splits one 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[] {
    if (typeof line !== 'string') {
        throw new Error('line must be a string');
    }

    const fields = [];
    let currentField = '';
    let insideQuote = false;

    for (const char of line) {
        if (char === '"') {
            insideQuote = !insideQuote;
        } else if (!insideQuote && char === ',') {
            if (currentField) {
                fields.push(currentField);
                currentField = '';
            }
        } else {
            currentField += char;
        }
    }

    if (currentField) {
        fields.push(currentField);
    }

    for (const field of fields) {
        const closeQuoteIndex = field.indexOf('"');

        if (closeQuoteIndex !== -1) {
            if ((field.length - 1) * 2 !== closeQuoteIndex + 1) {
                throw new Error(`quoted field '${field}' is never closed`);
            }
        } else {
            fields[fieldIndex] = field.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
        }
    }

    return fields;
}
```