Hyperlinkv0.8.0-beta.28

Function

Function.satisfiesconsteffect/Function.ts:279
<A>(): <B extends A>(b: B) => B

Ensures that the type of an expression matches some type, without changing the resulting type of that expression.

When to use

Use to check assignability while preserving the expression's precise inferred type.

Example (Checking an expression against a type)

import { Function } from "effect"
import * as assert from "node:assert"

const test1 = Function.satisfies<number>()(5 as const)
// ^? const test: 5
// @ts-expect-error
const test2 = Function.satisfies<string>()(5)
// ^? Argument of type 'number' is not assignable to parameter of type 'string'

assert.deepStrictEqual(Function.satisfies<number>()(5), 5)
utility typescast
export const satisfies = <A>() => <B extends A>(b: B) => b