import { Effect, pipe, Predicate, Data } from "effect";
type Result = {
a: number;
};
class MyError extends Data.TaggedError("MyError") {}
declare function getResultOrNull(): Effect.Effect<Result | null>;
declare function getNumberOrNull(): Effect.Effect<number | null>;
const predicateOkWithPrimaryType = (): Effect.Effect<number, MyError> => {
return pipe(
getNumberOrNull(),
Effect.filterOrFail(Predicate.isNotNull, () => new MyError()),
);
};
const predicateIssueWithComplexType = (): Effect.Effect<Result, MyError> => {
// Error described below happens here on the return line
return pipe(
getResultOrNull(),
Effect.filterOrFail(Predicate.isNotNull, () => new MyError()),
);
};
const functionOK = (): Effect.Effect<Result, MyError> => {
return pipe(
getResultOrNull(),
Effect.filterOrFail(
(r: Result | null): r is Result => r !== null,
() => new MyError(),
),
);
};
import { Effect, pipe, Predicate, Data } from "effect";
type Result = {
a: number;
};
class MyError extends Data.TaggedError("MyError") {}
declare function getResultOrNull(): Effect.Effect<Result | null>;
declare function getNumberOrNull(): Effect.Effect<number | null>;
const predicateOkWithPrimaryType = (): Effect.Effect<number, MyError> => {
return pipe(
getNumberOrNull(),
Effect.filterOrFail(Predicate.isNotNull, () => new MyError()),
);
};
const predicateIssueWithComplexType = (): Effect.Effect<Result, MyError> => {
// Error described below happens here on the return line
return pipe(
getResultOrNull(),
Effect.filterOrFail(Predicate.isNotNull, () => new MyError()),
);
};
const functionOK = (): Effect.Effect<Result, MyError> => {
return pipe(
getResultOrNull(),
Effect.filterOrFail(
(r: Result | null): r is Result => r !== null,
() => new MyError(),
),
);
};