```ts
/**
 * Splits a line of CSV into its fields on commas. Handles quoted fields that may contain commas
 * and doubled quotes inside them. Fields not enclosed in quotes are taken literally.
 *
 * @param {string} line - The CSV line to split.
 * @returns {string[]} An array containing the fields from 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++) {
    if (line[i] === '"') {
      if (i > 0 && line[i - 1] === '"' && !inQuotes) {
        // Escaped double quote inside a field
        field += '"';
      } else {
        inQuotes = !inQuotes;
      }
    } else if (line[i] === ',' && !inQuotes) {
      result.push(field.trim());
      field = '';
    } else {
      field += line[i];
    }
  }

  if (inQuotes) {
    throw new Error('Unquoted double quote found');
  }

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