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

Changed behavior in: std/encoding/csv.ts #1840

Closed
cfjello opened this issue Jan 23, 2022 · 3 comments
Closed

Changed behavior in: std/encoding/csv.ts #1840

cfjello opened this issue Jan 23, 2022 · 3 comments

Comments

@cfjello
Copy link

cfjello commented Jan 23, 2022

I have observed a changed behavior when using deno 1.18.0 and 'https://deno.land/std/encoding/csv.ts':

I'm am not sure if this is a bug or just some type related fallout.

Steps to reproduce

Here is some working code using [email protected]/encoding/csv.ts:

// import { parse as parseCsv } from 'https://deno.land/std/encoding/csv.ts';

 import {
    parse as parseCsv
  } from 'https://deno.land/[email protected]/encoding/csv.ts'


const content = await parseCsv(await Deno.readTextFile('csvTestItems.csv'), {
  skipFirstRow: true,
  parse: (e: any): unknown => {
    return { item: e.Name, quantity: e.Quantity, pricePerItem: `$${e.Price.toLocaleString('en-US')}`, isExpensive: e.Price >= 3000 };
  },
});

console.log(content);

This compiles and runs without problems:

deno run -A --unstable csvTest.ts

If you switch the import statement to the one at the very top in order use the newer csv.ts version:

import { parse as parseCsv } from 'https://deno.land/std/encoding/csv.ts';

you get the following Typescript error:

Check file:///C:/Work/GHCN-DAILY/csvTest.ts
error: TS2769 [ERROR]: No overload matches this call.
The last overload gave the following error.
Argument of type '{ skipFirstRow: true; parse: (e: any) => unknown; }' is not assignable to parameter of type 'ParseOptions'.
Object literal may only specify known properties, and 'parse' does not exist in type 'ParseOptions'.
parse: (e: any): unknown => {
^
at file:///C:/Work/GHCN-DAILY/csvTest.ts:11:3

TS2771 [ERROR]: The last overload is declared here.
export async function parse(
~~~~~
at https://deno.land/[email protected]/encoding/csv.ts:387:23

@kt3k
Copy link
Member

kt3k commented Jan 24, 2022

We changed parse behavior at v0.122.0 (PR: #1724)

We change the return type of parse() depending on the given options, and also removed the .parse option (because .parse option can be rewritten as .map(parse) call to the result).

If you don't have time to update the script, please use the pinned version below <= v0.121.0. If you can update the script, please try the script like the below:

import { 
  parse as parseCsv,
} from "https://deno.land/[email protected]/encoding/csv.ts";

const content = (await parseCsv(await Deno.readTextFile("csvTestItems.csv"), { 
  skipFirstRow: true,
})).map((e: any) => { 
  return { item: e.Name, quantity: e.Quantity, pricePerItem: `$${e.Price.toLocaleString("en-US")}`, isExpensive: e.Price >= 3000 };
});

console.log(content);

@cfjello
Copy link
Author

cfjello commented Jan 24, 2022

I will update - thanks for the quick reply!
One question though: is this documented?

@cfjello cfjello closed this as completed Jan 24, 2022
@kt3k
Copy link
Member

kt3k commented Jan 24, 2022

The informations about breaking changes are available at the release page of each version, for example, https://github.com/denoland/deno_std/releases/tag/0.122.0

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

No branches or pull requests

2 participants