Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Change record to 'any' type #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dvarnai
Copy link

@dvarnai dvarnai commented Feb 2, 2020

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

record should be of any type
@wdavidw
Copy link
Member

wdavidw commented Feb 2, 2020

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

@dvarnai
Copy link
Author

dvarnai commented Feb 3, 2020

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.

@wdavidw
Copy link
Member

wdavidw commented Dec 15, 2020

I think it has been fixed with #30

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants