Trouble with Typing a Function in a TypeScript Code Snippet
I'm a bit confused about why I can't type this function like this:
However, this works:
Shouldnt
// const makeStationRepo: Effect.Effect<StationRepo, never, TransactionContext>
// const makeFirefighterRepo: Effect.Effect<FirefighterRepo, never, TransactionContext>
function providePersistenceContext<A, E, R>(
self: Effect.Effect<A, E, R>
): Effect.Effect<
A,
E,
Exclude<R, StationRepo | FirefighterRepo> | TransactionContext
> {
// Type 'Exclude<R, FirefighterRepo>' is not assignable to type 'TransactionContext'
// Type 'R' is not assignable to type 'TransactionContext'
return self.pipe(
Effect.provideServiceEffect(StationRepo, makeStationRepo),
Effect.provideServiceEffect(FirefighterRepo, makeFirefighterRepo)
)
}// const makeStationRepo: Effect.Effect<StationRepo, never, TransactionContext>
// const makeFirefighterRepo: Effect.Effect<FirefighterRepo, never, TransactionContext>
function providePersistenceContext<A, E, R>(
self: Effect.Effect<A, E, R>
): Effect.Effect<
A,
E,
Exclude<R, StationRepo | FirefighterRepo> | TransactionContext
> {
// Type 'Exclude<R, FirefighterRepo>' is not assignable to type 'TransactionContext'
// Type 'R' is not assignable to type 'TransactionContext'
return self.pipe(
Effect.provideServiceEffect(StationRepo, makeStationRepo),
Effect.provideServiceEffect(FirefighterRepo, makeFirefighterRepo)
)
}However, this works:
function providePersistenceContext<A, E, R>(
self: Effect.Effect<A, E, R>
): Effect.Effect<
A,
E,
Exclude<Exclude<R, StationRepo>, FirefighterRepo> | TransactionContext
> {
return self.pipe(
Effect.provideServiceEffect(StationRepo, makeStationRepo),
Effect.provideServiceEffect(FirefighterRepo, makeFirefighterRepo)
)
}function providePersistenceContext<A, E, R>(
self: Effect.Effect<A, E, R>
): Effect.Effect<
A,
E,
Exclude<Exclude<R, StationRepo>, FirefighterRepo> | TransactionContext
> {
return self.pipe(
Effect.provideServiceEffect(StationRepo, makeStationRepo),
Effect.provideServiceEffect(FirefighterRepo, makeFirefighterRepo)
)
}Shouldnt
Exclude<R, StationRepo | FirefighterRepo> | TransactionContextExclude<R, StationRepo | FirefighterRepo> | TransactionContext be equivelent to Exclude<Exclude<R, StationRepo>, FirefighterRepo> | TransactionContextExclude<Exclude<R, StationRepo>, FirefighterRepo> | TransactionContext?