[英]Typescript papaparse No overload matches this call
我在 typescript 中使用Papaparse库。
import Papa from 'papaparse';
Papa.parse(filePath, {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
};
filepath
类型是string
我在文件路径上收到错误:
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.
在@types/papaparse中,有
/**
* 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;
我添加了complete
的 function 并像这样更新了我的代码:
import { parse, ParseResult } from 'papaparse';
parse(filePath, {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function (results: ParseResult<Record<string, unknown>>) {
/* ...code stuff... */
}
};
它有效。 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.