Hyperlinkv0.8.0-beta.28

Schema

Schema.isconsteffect/Schema.ts:1299
<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"
}
guards
Source effect/Schema.ts:12991 lines
export const is = SchemaParser.is
Referenced by 1 symbols