node-stream-transform icon indicating copy to clipboard operation
node-stream-transform copied to clipboard

Change record to 'any' type

Open dvarnai opened this issue 5 years ago • 3 comments

If records is Array<any> a record should just be any type

dvarnai avatar Feb 02 '20 14:02 dvarnai

Array<any> and any doesn't seem the same, am I missing something ?

wdavidw avatar Feb 02 '20 22:02 wdavidw

Well records and record are both Array<any> so one of them must be wrong (if record is indeed Array<any> shouldn't records be Array<Array<any>>?).

IMO record is wrong and should just simply be any. I'm using this with your csv-parse module with columns: true and record is not even an Array:

const parser = csvparse({columns: true});
const transformer = transform((record: Array<any>, cb) => {
    console.log(typeof record, record instanceof Array); // prints "object false"
})

request.get('https://ourairports.com/data/airports.csv')
.pipe(parser)
.pipe(transformer);

Furthermore, accessing properties of record fails at compilation time with Array<any>:

Property 'id' does not exist on type 'any[]'.

With my fix it's possible to explicity tell the compiler the type of record in the function definition. Without that I could only disable type checking by explicitly setting record to any and then doing type casting, but that will lead to eslint warnings (unexpected any):

const transformer = transform((e: any, cb) => {
            e = e as {[key: string]: string};
}

Hope that makes sense.

dvarnai avatar Feb 03 '20 10:02 dvarnai

I think it has been fixed with #30

wdavidw avatar Dec 15 '20 08:12 wdavidw