2

I use Papaparse lib in typescript.

import Papa from 'papaparse';

Papa.parse(filePath, {
  download: true, 
  header: true,
  dynamicTyping: true,
  skipEmptyLines: true,
};

filepath type is string

I get error on filePath:

No overload matches this call. The last overload generated the following error. The 'string' type argument is not assignable to the 'unique symbol' type parameter.

In @types/papaparse, there is


/**
 * Parse local files
 * @param file a File object obtained from the DOM.
 * @param config a config object which contains a callback.
 * @returns Doesn't return anything. Results are provided asynchronously to a callback function.
 */
// tslint:disable-next-line: no-unnecessary-generics
export function parse<T, TFile extends LocalFile = LocalFile>(file: TFile, config: ParseLocalConfig<T, TFile>): void;

/**
 * Parse remote files
 * @param url the path or URL to the file to download.
 * @param config a config object.
 * @returns Doesn't return anything. Results are provided asynchronously to a callback function.
 */
// tslint:disable-next-line: no-unnecessary-generics
export function parse<T>(url: string, config: ParseRemoteConfig<T>): void;

Hasina Njaratin
  • 401
  • 1
  • 6
  • 17
  • This import form...`import Papa from 'papaparse';` is used to import `default` exports. Why don't you try `import { parse } from 'papaparse';` and then use the function directly? – Nalin Ranjan Mar 11 '22 at 06:59
  • 1
    I have the impression that you are missing the function `complete(results: ParseResult, file: TInput): void` from the `config` argument. This may be confusing the compiler to call a different overload than the one you think you are calling. – Nikos Paraskevopoulos Mar 11 '22 at 07:53
  • i updated the body question. i still get errors – Hasina Njaratin Mar 11 '22 at 08:10

1 Answers1

4

I added complete function and updated my code like this:

import { parse, ParseResult } from 'papaparse';

parse(filePath, {
  download: true, 
  header: true,
  dynamicTyping: true,
  skipEmptyLines: true,
  complete: function (results: ParseResult<Record<string, unknown>>) {
    /* ...code stuff... */
  }
};

and it works. thx

Hasina Njaratin
  • 401
  • 1
  • 6
  • 17