```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[] {
  const fields = [];
  let currentField = '';
  let inQuote = false;
  let quoteCount = 0;

  for (let i = 0; i < line.length; i++) {
    const char = line[i];

    if (char === '"') {
      if (inQuote) {
        quoteCount++;
      } else {
        inQuote = true;
      }
    }

    if (char === ',' && !inQuote) {
      fields.push(currentField.trim());
      currentField = '';
    } else {
      currentField += char;
    }

    if (quoteCount > 0) {
      continue;
    }

    if (currentField !== '') {
      fields.push(currentField);
      currentField = '';
    }
  }

  if (inQuote) {
    throw new Error('Quoted field not closed');
  }

  return fields;
}
```