Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Transforming to a different type in Typescript? #356

Closed
1 of 2 tasks
bastiankoetsier opened this issue May 17, 2020 · 2 comments
Closed
1 of 2 tasks

[BUG] Transforming to a different type in Typescript? #356

bastiankoetsier opened this issue May 17, 2020 · 2 comments

Comments

@bastiankoetsier
Copy link

Describe the bug
First of all: Thank you very much for this awesome library!
I was trying to use it in typescript but I have a small issue where it is not possible(?) to use transform to map from the InputType to a different OutputType having same properties but different types (sorry for the bad wording, hopefully the example makes this more clear 😅)

Parsing or Formatting?

  • Formatting
  • Parsing

To Reproduce
My code:

type InputRow = {
  clicks: string;
};

type OutputRow = {
  clicks: number;
};
...
  return new Promise((resolve, reject) => {
    const result: any[] = [];
    fs.createReadStream(path.resolve(__dirname, inputFile))
      .pipe(
        parse<InputRow, OutputRow>({ headers: true })
      )
      .on("error", (error: Error) => console.error(error))
      .on("data", (row: any) => {
        result.push(row);
      })
      .transform((data: InputRow): OutputRow => {
        return {
          clicks: parseInt(data.clicks, 10),
         };
      })
      .on("end", () => resolve(result));
  });

I was checking the type-definitions and found

export declare const parse: <I extends Row, O extends Row>...

Is there any reason why O needs to extends Row?

Expected behavior
The given output type should not extend Row
Screenshots
screenshot

If you have any questions, just let me know!

@doug-martin
Copy link
Contributor

I added this in v4.2.0 let me know if you run into any additional issues.

Thanks again!

@bastiankoetsier
Copy link
Author

Works like a charm! Thanks for the very quick response @doug-martin !

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

No branches or pull requests

3 participants