0

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?

Simon
  • 621
  • 4
  • 21

1 Answers1

1

You predicate needs to operate on Timestamps, not numbers

const predicate = (s: string, v: Timestamp) =>
  s === "date" && v.date > 0
bugs
  • 14,631
  • 5
  • 48
  • 52