Confusing Question
Hi, quick question as it's confusing me little bit.
The following program showcase a potential error "E" as
See my comment below:
The following program showcase a potential error "E" as
"hi from doSomething""hi from doSomething" (cuz of the methods definition within the interface - see "doSomething"), which will actually nevernever happen (cuz of its implementation).See my comment below:
interface SomeDependency {
doThis: () => Effect.Effect<never, never, string>;
}
const SomeDependency = Context.Tag<SomeDependency>();
interface TheService {
doSomething: (
id: string
) => Effect.Effect<never, "hi from doSomething", string>;
}
const TheService = Context.Tag<TheService>();
const makeLiveService = pipe(
SomeDependency,
Effect.map((someDependency) =>
TheService.of({
doSomething: (id) => someDependency.doThis(),
})
)
) satisfies Effect.Effect<SomeDependency, never, TheService>;
const binding = Layer.effect(TheService, makeLiveService) satisfies Layer.Layer<
SomeDependency,
never,
TheService
>;
/*
Question: why it doesn't complain..?
- as doSomething has a "E" defined as in the interface: "hi from doSomething"
- and its implementation has a "E" defined as: never
This confusing me little bit as the program showcase a potential "E" as "hi from doSomething"
which will actually never happen.
*/
const program = pipe(
TheService,
Effect.flatMap((theService) => theService.doSomething("4")),
(x) => x,
Effect.provideSomeLayer(binding),
(x) => x,
Effect.provideService(
SomeDependency,
SomeDependency.of({
doThis: () => Effect.succeed("d"),
})
)
) satisfies Effect.Effect<never, "hi from doSomething", string>;interface SomeDependency {
doThis: () => Effect.Effect<never, never, string>;
}
const SomeDependency = Context.Tag<SomeDependency>();
interface TheService {
doSomething: (
id: string
) => Effect.Effect<never, "hi from doSomething", string>;
}
const TheService = Context.Tag<TheService>();
const makeLiveService = pipe(
SomeDependency,
Effect.map((someDependency) =>
TheService.of({
doSomething: (id) => someDependency.doThis(),
})
)
) satisfies Effect.Effect<SomeDependency, never, TheService>;
const binding = Layer.effect(TheService, makeLiveService) satisfies Layer.Layer<
SomeDependency,
never,
TheService
>;
/*
Question: why it doesn't complain..?
- as doSomething has a "E" defined as in the interface: "hi from doSomething"
- and its implementation has a "E" defined as: never
This confusing me little bit as the program showcase a potential "E" as "hi from doSomething"
which will actually never happen.
*/
const program = pipe(
TheService,
Effect.flatMap((theService) => theService.doSomething("4")),
(x) => x,
Effect.provideSomeLayer(binding),
(x) => x,
Effect.provideService(
SomeDependency,
SomeDependency.of({
doThis: () => Effect.succeed("d"),
})
)
) satisfies Effect.Effect<never, "hi from doSomething", string>;