Hyperlinkv0.8.0-beta.28

Layer

Layer.satisfiesErrorTypeconsteffect/Layer.ts:2385
<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'
utility types
Source effect/Layer.ts:23852 lines
export const satisfiesErrorType =
  <E>() => <ROut, E2 extends E, RIn>(layer: Layer<ROut, E2, RIn>): Layer<ROut, E2, RIn> => layer