我正在使用 Papaparse 和 Typescript 來決議本地檔案,它運行良好。
我這樣做是這樣的:
parse(file, {
header: true,
dynamicTyping: true,
complete: (results) =>
console.log(results)
});
但我想強烈輸入結果。我有一個介面,決議的結果總是會回傳一個具有以下屬性的物件陣列:
export interface Person {
name: string;
age: number;
location: string;
}
我們如何輸入結果?
我找到了這個Reddit 執行緒并嘗試了他們的解決方案,但它不起作用:
parse<Person[]>(file, {
header: true,
dynamicTyping: true,
complete: (results: Person) =>
console.log(JSON.stringify(results.age))
});
uj5u.com熱心網友回復:
complete回呼不回傳Person物件。
該函式應如下所示:
import {ParseResult} from 'papaparse';
function(results: ParseResult<Person>){ ...}
請參閱https://www.papaparse.com/docs#results和型別檔案中的第 255 行
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/466586.html
上一篇:在CSV檔案中轉義單引號
