fp-ts filterWithIndex "index signatures are incompatible"
fp-ts filterWithIndex "index signatures are incompatible"
通过 fp-ts
学习打字稿让我遇到麻烦。
我收到以下错误:
Type 'Record<string, number>' is not assignable to type 'Timestamps'.
Index signatures are incompatible.
Type 'number' is not assignable to type 'Timestamp'.(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)
}
我应该更改什么才能使我的代码正常工作?
您的谓词需要对 Timestamp
s 进行操作,而不是 number
s
const predicate = (s: string, v: Timestamp) =>
s === "date" && v.date > 0
通过 fp-ts
学习打字稿让我遇到麻烦。
我收到以下错误:
Type 'Record<string, number>' is not assignable to type 'Timestamps'. Index signatures are incompatible. Type 'number' is not assignable to type 'Timestamp'.(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)
}
我应该更改什么才能使我的代码正常工作?
您的谓词需要对 Timestamp
s 进行操作,而不是 number
s
const predicate = (s: string, v: Timestamp) =>
s === "date" && v.date > 0