-
I have 2 async functions with the following signatures: export type SmaId = string;
public async resolveSmaIds(
explorationRequest: ExplorationRequest
): Promise<Either<ExternalExplorationProviderUnavailable, SmaId[]>> {};
public async getAllByIds(
smaIds: SmaId[]
): TaskEither<SmasNotFound, Sma[]> {}; And I need to combine these functions to an async pipeline that returns I tried to achieve this with the following code: import { pipe } from 'fp-ts/lib/function';
import { taskEither } from 'fp-ts';
const pipeline = pipe(
explorationRequest,
this.resolveSmaIdsProvider.resolveSmaIds,
taskEither.chain(this.smaRepository.getAllByIds)
); I am getting the following error from the TS compiler: How do I should resolve this error? Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The signature of If you can rewrite import { pipe } from 'fp-ts/function'
import * as TE from 'fp-ts/TaskEither'
declare function resolveSmaIds(
explorationRequest: ExplorationRequest
): TE.TaskEither<ExternalExplorationProviderUnavailable, SmaId[]>
declare function getAllByIds(smaIds: SmaId[]): TE.TaskEither<SmasNotFound, Sma[]>
declare const explorationRequest: ExplorationRequest
pipe(
explorationRequest,
resolveSmaIds,
TE.chainW(getAllByIds)
) Otherwise you could rewrite your pipe like this: import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'
import * as TE from 'fp-ts/TaskEither'
declare function resolveSmaIds(
explorationRequest: ExplorationRequest
): Promise<E.Either<ExternalExplorationProviderUnavailable, SmaId[]>>
declare function getAllByIds(smaIds: SmaId[]): TE.TaskEither<SmasNotFound, Sma[]>
declare const explorationRequest: ExplorationRequest
pipe(
() => resolveSmaIds(explorationRequest), // <--
TE.chainW(getAllByIds)
) |
Beta Was this translation helpful? Give feedback.
The signature of
TaskEither<E, A>
is() => Promise<Either<E, A>>
while the return type ofresolveSmaIds
isPromise<Either<E, A>>
. In other words,TaskEither
is a thunkedPromise
whileresolveSmaIds
returns a barePromise
. Also, since theLeft
types are different between the functions,TaskEither.chainW
is needed to widen the type on the left.If you can rewrite
resolveSmaIds
to return aTaskEither
, that would be the “idiomatic” way to do it: