Home > Blockchain >  fp-ts filterWithIndex "index signatures are incompatible"
fp-ts filterWithIndex "index signatures are incompatible"

Time:01-11

Learning typescript via fp-ts leads me to trouble.

I'm getting the following error:

Type 'Record<string, number>' is not assignable to type 'Timestamps'. Index signatures are incompatible. Type 'number' is not assignable to type 'Timestamp'.(2322)

Code below:

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)
}

What should i change for my code to work?

CodePudding user response:

You predicate needs to operate on Timestamps, not numbers

const predicate = (s: string, v: Timestamp) =>
  s === "date" && v.date > 0
  •  Tags:  
  • Related