<S extends Constraint>(schema: S): <I>(input: I) => input is I & S["Type"]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"
}export const const is: <S extends Schema.Constraint>(
schema: S
) => <I>(input: I) => input is I & S["Type"]
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"
}
is = import SchemaParserSchemaParser.function is<S extends Schema.Constraint>(
schema: S
): <I>(input: I) => input is I & S["Type"]
Creates a type guard that checks whether an input satisfies the schema's decoded
type side.
When to use
Use to build a type guard for checking the decoded side of a schema without
exposing issue details.
Details
The guard returns true on successful validation and false when validation
fails only with schema issues, without exposing issue details.
Gotchas
Only causes made entirely of schema issues are converted to false. Causes
that contain defects, interruptions, or asynchronous work at this synchronous
boundary throw an Error whose cause is the underlying Cause.
is