Package: effect
Module: Schema
Creates a type guard function that checks if a value conforms to a given schema.
Details
This function returns a predicate that performs a type-safe check, narrowing
the type of the input value if the check passes. The predicate returns false
for schema mismatches.
Gotchas
Only causes made entirely of schema issues are converted to false. Causes
that contain defects, interruptions, or other non-schema reasons throw
instead.
Example (Defining a basic type guard)
import { Schema } from "effect"
const isString = Schema.is(Schema.String)
console.log(isString("hello")) // true
console.log(isString(42)) // false
// Type narrowing in action
const value: unknown = "hello"
if (isString(value)) {
// value is now typed as string
console.log(value.toUpperCase()) // "HELLO"
}
Signature
declare const is: <S extends Constraint>(schema: S) => <I>(input: I) => input is I & S["Type"]
Since v3.10.0