```ts
/**
 * Splits a line of CSV into its fields on commas.
 * Fields 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.
 *
 * @param line - A line of CSV data to be parsed.
 * @returns An array of strings representing the fields in the CSV line.
 */
export function parseCsvLine(line: string): string[] {
  const result: string[] = [];
  let field = '';
  let inQuotes = false;

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

    if (char === '"') {
      if (!inQuotes) {
        inQuotes = true;
        continue;
      } else {
        if (i + 1 < line.length && line[i + 1] === '"') {
          field += char;
          i++; // Skip the next quotes as it's an escaped quote
        } else {
          inQuotes = false;
        }
      }
    }

    if (!inQuotes && char === ',') {
      result.push(field.trim());
      field = '';
      continue;
    }

    field += char;
  }

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

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