<E>(): <ROut, E2 extends E, RIn>(
layer: Layer<ROut, E2, RIn>
) => Layer<ROut, E2, RIn>Ensures that a layer's error type extends a given type E.
Details
This function provides compile-time type checking to ensure that the error type of a layer conforms to a specific type constraint.
Example (Constraining layer error types)
import { Layer } from "effect"
declare const ErrorLayer: Layer.Layer<never, Error, never>
declare const TypeErrorLayer: Layer.Layer<never, TypeError, never>
declare const StringLayer: Layer.Layer<never, string, never>
// Define a constraint that the error type must be an Error
const satisfiesError = Layer.satisfiesErrorType<Error>()
// This works - Layer<never, TypeError, never> extends Layer<never, Error, never>
const validLayer = satisfiesError(TypeErrorLayer)
// This would cause a TypeScript compilation error:
// const invalidLayer = satisfiesError(StringLayer)
// ^^^^^^^^^^^
// Type 'string' is not assignable to type 'Error'export const const satisfiesErrorType: <E>() => <
ROut,
E2 extends E,
RIn
>(
layer: Layer<ROut, E2, RIn>
) => Layer<ROut, E2, RIn>
Ensures that a layer's error type extends a given type E.
Details
This function provides compile-time type checking to ensure that the error
type of a layer conforms to a specific type constraint.
Example (Constraining layer error types)
import { Layer } from "effect"
declare const ErrorLayer: Layer.Layer<never, Error, never>
declare const TypeErrorLayer: Layer.Layer<never, TypeError, never>
declare const StringLayer: Layer.Layer<never, string, never>
// Define a constraint that the error type must be an Error
const satisfiesError = Layer.satisfiesErrorType<Error>()
// This works - Layer<never, TypeError, never> extends Layer<never, Error, never>
const validLayer = satisfiesError(TypeErrorLayer)
// This would cause a TypeScript compilation error:
// const invalidLayer = satisfiesError(StringLayer)
// ^^^^^^^^^^^
// Type 'string' is not assignable to type 'Error'
satisfiesErrorType =
<function (type parameter) E in <E>(): <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>) => Layer<ROut, E2, RIn>E>() => <function (type parameter) ROut in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>ROut, function (type parameter) E2 in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>E2 extends function (type parameter) E in <E>(): <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>) => Layer<ROut, E2, RIn>E, function (type parameter) RIn in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>RIn>(layer: Layer<ROut, E2, RIn>(parameter) layer: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<ROut>, E2, RIn>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
layer: interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<function (type parameter) ROut in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>ROut, function (type parameter) E2 in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>E2, function (type parameter) RIn in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>RIn>): interface Layer<in ROut, out E = never, out RIn = never>A Layer describes how to build one or more services for dependency injection.
When to use
Use to model construction of application services for dependency injection,
especially when services have dependencies, can fail during construction, or
need scoped setup and release.
Details
A Layer<ROut, E, RIn> represents ROut as the services this layer
provides, E as the possible errors during layer construction, and RIn as
the services this layer requires as dependencies.
Layer<function (type parameter) ROut in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>ROut, function (type parameter) E2 in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>E2, function (type parameter) RIn in <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn>RIn> => layer: Layer<ROut, E2, RIn>(parameter) layer: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<ROut>, E2, RIn>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
layer