GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — on_record type definition does not allow changing the type of the record · Issue #461 · adaltas/node-csv

on_record type definition does not allow changing the type of the record #461

New issue
Copy link
New issue
Copy link
Closed
Closed
on_record type definition does not allow changing the type of the record#461
Copy link

Description

@seamuslowry
seamuslowry
opened on Jul 20, 2025
Issue body actions

Describe the bug

On version 6.0.0, the type of Options has changed such that the on_record field must return the same type as is provided. This makes it less useful for transforming the data as I understand the purpose of the field to be.

To Reproduce

In my example, I take a CSV of research papers where the first few columns are defined but the remainder will all be separate author names, which will be varying lengths. I want to use on_record to transform the string array into an object with a single authors array field using the code below (simplified for reproduction).

import { parse } from 'csv-parse';

const input = `Topic One,Title One,Author One
Topic Two,Title Two,Author One,Author Two
Topic Three,Title Three,Author One,Author Two,Author Three
Topic Four,Title Four,Author One`;

parse(input, {
  // @ts-expect-error this object is not recognized as Options because on_record takes in string[] but returns object
  relax_column_count: true,
  on_record: r => {
    const [topic, title, ...authors] = r;
    return { topic, title, authors };
  },
}).on('data', console.log);

This code functions as expected and outputs the below

{ topic: 'Topic One', title: 'Title One', authors: [ 'Author One' ] }
{
  topic: 'Topic Two',
  title: 'Title Two',
  authors: [ 'Author One', 'Author Two' ]
}
{
  topic: 'Topic Three',
  title: 'Title Three',
  authors: [ 'Author One', 'Author Two', 'Author Three' ]
}
{ topic: 'Topic Four', title: 'Title Four', authors: [ 'Author One' ] }

but builds using TypeScript will fail until they expect or ignore the error because the type definition prevents the object from being typed as Options

Activity

  1. wdavidw
    added 3 commits that reference this issue on Aug 14, 2025

    feat(csv-parse): with option `columns` (fix #461 #464)

    This issue will close once commit 66ea728 is merged into the 'master' branch.
    66ea728

    feat(csv-parse): with option `columns` (fix #461 #464 #466)

    This issue will close once commit 50d6613 is merged into the 'master' branch.
    50d6613

    feat(csv-parse): with option `columns` (fix #461 #464 #466)

    This issue will close once commit 63a3c7e is merged into the 'master' branch.
    63a3c7e
  2. wdavidw
    closed this as completedin 9ddbabfon Oct 6, 2025
  3. wdavidw
    added a commit that references this issue on Oct 6, 2025

    feat(csv-parse): returned type generic for `on_record` (fix adaltas#461

    This issue will close once commit 9ddbabf is merged into the 'master' branch.
    9ddbabf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.