通过fp-ts学习打字稿会给我带来麻烦。
我得到了以下错误:
类型'Record‘不能指定键入’时间戳‘。索引签名不兼容。输入'number‘不能指定键入’时间戳‘。(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)
}我应该更改哪些代码才能工作?
发布于 2022-01-10 15:28:34
您的谓词需要在Timestamps上操作,而不是numbers。
const predicate = (s: string, v: Timestamp) =>
s === "date" && v.date > 0https://stackoverflow.com/questions/70654765
复制相似问题