```ts
/**
 * Parses one CSV line into its fields according to RFC 4180 rules.
 * @param line A single CSV line (no newlines).
 * @returns An array of string fields.
 * @throws Error for invalid input or malformed CSV.
 */
export function parseCsvLine(line: string): string[] {
  if (typeof line !== 'string') {
    throw new Error('line must be a string');
  }

  const result: string[] = [];
  let currentField = '';
  let inQuotes = false;
  let i = 0;

  while (i < line.length) {
    const char = line[i];

    if (!inQuotes) {
      if (char === '"') {
        // Start of a quoted field
        inQuotes = true;
        i++;
      } else if (char === ',') {
        // End of current field
        result.push(currentField);
        currentField = '';
        i++;
      } else {
        // Regular character in unquoted field
        if (char === '"') {
          throw new Error('quote inside unquoted field');
        }
        currentField += char;
        i++;
      }
    } else {
      // Inside a quoted field
      if (char === '"') {
        // Check for escaped quote ("")
        if (i + 1 < line.length && line[i + 1] === '"') {
          currentField += '"';
          i += 2;
        } else {
          // End of quoted field
          inQuotes = false;
          i++;
          // After closing quote, must be end of line or comma
          if (i < line.length && line[i] !== ',') {
            throw new Error('invalid character after closing quote');
          }
        }
      } else {
        currentField += char;
        i++;
      }
    }
  }

  // Push the last field
  result.push(currentField);

  // Check for unterminated quoted field
  if (inQuotes) {
    throw new Error('unterminated quoted field');
  }

  return result;
}
```