Package: effect
Module: Layer
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'
Signature
declare const satisfiesErrorType: <E>() => <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>) => Layer<ROut, E2, RIn>
Since v4.0.0