```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++; // Move past the opening quote
      let quoted = false;

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

        if (c === '"') {
          // Check if next char is also a quote (doubled quote)
          if (i + 1 < line.length && line[i + 1] === '"') {
            field += '"';
            i += 2; // Skip both quotes
            continue;
          } else {
            // This is the closing quote
            quoted = true;
            i++;
            break;
          }
        }

        field += c;
        i++;
      }

      if (!quoted) {
        throw new Error('Unterminated quoted field');
      }

      // After closing quote, must be comma or end of line
      if (i < line.length && line[i] !== ',') {
        throw new Error('Invalid character after closing quote');
      }
    } else if (char === ',') {
      result.push(field);
      field = '';
      i++;
    } else {
      field += char;
      i++;
    }
  }

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

  return result;
}
```