【发布时间】:2022-01-10 15:23:15
【问题描述】:
通过fp-ts 学习打字稿会给我带来麻烦。
我收到以下错误:
类型 'Record
' 不可分配给类型 '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)
}
我应该改变什么才能让我的代码工作?
【问题讨论】:
标签: typescript functional-programming fp-ts