```ts
export function parseCsvLine(line: string): string[] {
  if (typeof line !== 'string') {
    throw new Error('Input must be a string');
  }

  const result: string[] = [];
  let i = 0;
  let field = '';

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

    if (char === '"') {
      // If we're not at the start of a new field, this is an error
      if (field !== '') {
        throw new Error('Quote inside unquoted field');
      }

      i++; // Skip the opening quote
      let quotedField = '';
      
      while (i < line.length) {
        if (line[i] === '"') {
          // Check for doubled quote
          if (i + 1 < line.length && line[i + 1] === '"') {
            quotedField += '"';
            i += 2; // Skip both quotes
          } else {
            // End of quoted field
            i++; // Skip the closing quote
            
            // Ensure next character is either comma or end of string
            if (i < line.length && line[i] !== ',') {
              throw new Error('Invalid character after closing quote');
            }
            
            field = quotedField;
            break;
          }
        } else {
          quotedField += line[i];
          i++;
        }
      }
      
      // If we reached end of string without finding closing quote
      if (i >= line.length && line[line.length - 1] !== '"') {
        throw new Error('Unterminated quoted field');
      }
      
      result.push(field);
      field = '';
    } else if (char === ',') {
      result.push(field);
      field = '';
      i++;
    } else {
      field += char;
      i++;
    }
  }

  // Add the last field
  result.push(field);

  return result;
}
```