Effect CommunityEC
Effect Community2y ago
1 reply
Industrial

How does the Context argument of Effect work?

export const between = <A extends Date, E, R>(timeframe: Timeframe) =>
  (startDateE: E.Effect<A, E, R>) =>
    (endDateE: E.Effect<A, E, R>) =>
      pipe(
        E.Do,
        E.bind('startDate', () =>
          startDateE),
        E.bind('endDate', () =>
          endDateE),
        E.filterOrFail(
          ({ startDate, endDate }) =>
            endDate.valueOf() < startDate.valueOf(),
          () =>
            new DateRangeError({ message: 'End date is before start date.' }),
        ),
        E.filterOrFail(
          ({ startDate, endDate }) =>
            endDate.valueOf() === startDate.valueOf(),
          () =>
            new DateRangeError({ message: 'End date is equal to start date.' }),
        ),
        E.flatMap(({ endDate }) =>
          pipe(
            startDateE,
            normalizeStartDate(timeframe),
            pipe(
              E.succeed(endDate),
              generateDates<A, Cause.NoSuchElementException | E, R>(timeframe),
            ),
          )),
      )


When I try to run it with E.runSync(between(timeframe)(startDateE)(endDateE))) I get the error:

Argument of type 'Effect<Date[], unknown, unknown>' is not assignable to parameter of type 'Effect<Date[], unknown, never>'.
  Type 'unknown' is not assignable to type 'never'.ts(2345)
Was this page helpful?