通過學習打字稿fp-ts給我帶來了麻煩。
我收到以下錯誤:
型別 'Record<string, number>' 不可分配給型別 'Timestamps'。索引簽名不兼容。型別“數字”不可分配給型別“時間戳”。(2322)
下面的代碼:
import * as R from "fp-ts/dist/esm/Record";
interface Timestamp {
date: number
id: string
}
interface Timestamps {
[key: string]: Timestamp
}
const MyFunction = (dates: Timestamps): Timestamps => {
const predicate = (s: string, v: number) => s === "date" && v > 0 // 0 milliseconds
return R.filterWithIndex(predicate)(dates)
}
我應該改變什么才能讓我的代碼作業?
uj5u.com熱心網友回復:
您的謂詞需要對Timestamps進行操作,而不是numbers
const predicate = (s: string, v: Timestamp) =>
s === "date" && v.date > 0
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/407774.html
標籤:
上一篇:在圖庫中使用虛擬滾動
下一篇:在JSON檔案中使用字典
