node-csv icon indicating copy to clipboard operation
node-csv copied to clipboard

Options type declaration is missing underlying stream properties

Open valeneiko opened this issue 4 years ago • 0 comments

Describe the bug

csv-parse and csv-stringify (possibly others too) have Options class defined, which does not extend corresponding Stream options.

To Reproduce

import * as csvParse from 'csv-parse';
const csvReader = csvParse({ highWaterMark: 65 * 1024 });

Will produce a type error, because highWaterMark is not defined on parse.Options, but if compiled (ignoring the error) the code works as expected.

Additional context The Options interface should extend DuplexOptions interface. But encoding property is defined in both and is not compatible, so may need to be omitted from one of the types.

The following d.ts definition file can be use as a workaround:

import { DuplexOptions } from 'stream';

declare module 'csv-stringify' {
    interface Options extends Omit<DuplexOptions, 'encoding'> {}
}

declare module 'csv-parse' {
    interface Options extends Omit<DuplexOptions, 'encoding'> {}
}

valeneiko avatar Jul 26 '21 11:07 valeneiko