Reputation: 5917
I'm trying to call a function from within ReaderTaskEither that returns TaskEither but can't seem to get the types right.
Can someone please tell me what I'm doing wrong?
Thank you.
import * as E from "fp-ts/Either";
import * as RTE from "fp-ts/ReaderTaskEither";
import * as TE from "fp-ts/TaskEither";
import { pipe } from "fp-ts/function";
type Env = { arid: string };
const getValues = (id: string): TE.TaskEither<Error, number[]> => TE.fromEither(E.right([]));
class Result {
constructor(public values: number[]) {}
}
export function sut(): RTE.ReaderTaskEither<Env, Error, Result> {
return pipe(
/*
Argument of type 'ReaderTaskEither<Env, Error, Env>' is not assignable to parameter of type 'ReaderTaskEither<unknown, Error, Env>'.
Type 'unknown' is not assignable to type 'Env'
*/
RTE.ask<Env, Error>(),
RTE.chain((env) =>
pipe(
getValues(env.arid),
TE.map((e) => new Result(e)),
RTE.fromTaskEither
)
)
);
}
Upvotes: 0
Views: 28
Reputation: 5917
Found it.
import * as E from "fp-ts/Either";
import * as RTE from "fp-ts/ReaderTaskEither";
import * as TE from "fp-ts/TaskEither";
import { pipe } from "fp-ts/function";
type Env = { arid: string };
const getValues = (id: string): TE.TaskEither<Error, number[]> => TE.fromEither(E.right([]));
class Result {
constructor(public values: number[]) {}
}
export function sut(): RTE.ReaderTaskEither<Env, Error, Result> {
return pipe(
/*
Argument of type 'ReaderTaskEither<Env, Error, Env>' is not assignable to parameter of type 'ReaderTaskEither<unknown, Error, Env>'.
Type 'unknown' is not assignable to type 'Env'
*/
RTE.ask<Env, Error>(),
RTE.chain((env) =>
pipe(
getValues(env.arid),
TE.map((e) => new Result(e)),
RTE.fromTaskEither<Error, Result,Env> // here
)
)
);
}
Upvotes: 0