javascript - Typescript papaparse Ingen överbelastning matchar detta anrop
Jag använder Papaparse-biblioteket i TypeScript.
import Papa from 'papaparse';
Papa.parse(filePath, {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
};
filepath-typen är string
Jag får ett fel på 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.
I @types/papaparse finns det
/**
* 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;
Svar #1
Jag lade till complete-funktionen och uppdaterade min kod så här:
import { parse, ParseResult } from 'papaparse';
parse(filePath, {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function (results: ParseResult<Record<string, unknown>>) {
/* ...code stuff... */
}
};
och det fungerar. tack
