```ts
export function parseCsvLine(line: string): string[] {
  const fields = [];
  let field = '';
  let inQuotes = false;

  for (let i = 0; i < line.length; ++i) {
    if (inQuotes) {
      // Inside a quoted field: keep going until we hit an unescaped quote or the end of the line.
      field += line[i];

      if (line[i] === '"') {
        if (i + 1 < line.length && line[i+1] === '"') { // Escaped quote inside a quoted field.
          ++i;
        } else {
          // Otherwise, this is the closing quote of the field — end it and add to our results.
          inQuotes = false;
          fields.push(field);
          field = '';
        }
      }
    } else if (line[i] === '"') { // Starting a quoted field.
      if (i + 1 < line.length && line[i+1] === '"') {
        throw new Error('Invalid CSV: found unexpected quote at index ' + i);
      }
      inQuotes = true;
    } else if (line[i] === ',') { // Regular comma delimits fields.
      fields.push(field);
      field = '';
    } else { // Just a normal character inside the field.
      field += line[i];
    }
  }

  if (inQuotes) {
    throw new Error('Invalid CSV: unclosed quoted field at end of line');
  }

  // Add any remaining characters in the last field to our results.
  fields.push(field);

  return fields;
}
```