```ts
/**
 * Parses a single line of CSV into its fields on commas,
 * with special handling for quoted values containing commas or double quotes.
 * Throws Error if a quote appears inside an unquoted field.
 * @param line The input string to parse.
 * @returns An array of string fields.
 */
export function parseCsvLine(line: string): string[] {
  const result: string[] = [];
  let inQuotes = false;
  let quotedField = "";
  let currentField = "";

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

    if (char === '"') {
      inQuotes = !inQuotes;
      if (!inQuotes) {
        result.push(quotedField.trim());
        quotedField = "";
      }
    } else if (char === ',' && !inQuotes) {
      if (currentField !== "") {
        result.push(currentField);
      }
      currentField = "";
    } else {
      currentField += char;
    }

    if (i === line.length - 1 && inQuotes) {
      throw new Error("Unmatched quote at the end of the line.");
    }
  }

  return result;
}
```