Skip to content

API Reference

This is a quick reference for Effect Schema's API. For detailed documentation, see the guide sections.

Schema Types

Primitives

SchemaTypeDescription
Schema.StringstringAny string
Schema.NumbernumberAny number (includes NaN, ±Infinity)
Schema.Booleanbooleantrue or false
Schema.BigIntFromSelfbigintBigInt value
Schema.SymbolFromSelfsymbolSymbol value
Schema.Nullnullnull only
Schema.Undefinedundefinedundefined only
Schema.Voidvoidvoid (accepts undefined)
Schema.UnknownunknownAny value
Schema.AnyanyAny value (unsafe)
Schema.NeverneverNo value valid
Schema.ObjectobjectNon-null objects

Literals

SchemaTypeDescription
Schema.Literal("a", "b")"a" | "b"Exact literal values
Schema.Enums(E)ETypeScript enum
Schema.UniqueSymbolFromSelf(s)typeof sSpecific symbol

Objects

SchemaTypeDescription
Schema.Struct({...}){...}Object with properties
Schema.Record({key, value})Record<K, V>Dynamic keys
Schema.TaggedStruct(tag, {...}){_tag: T, ...}Tagged object

Collections

SchemaTypeDescription
Schema.Array(s)readonly T[]Variable-length array
Schema.NonEmptyArray(s)readonly [T, ...T[]]At least one element
Schema.Tuple(a, b, c)readonly [A, B, C]Fixed-length tuple

Unions

SchemaTypeDescription
Schema.Union(a, b)A | BUnion of schemas
Schema.NullOr(s)T | nullNullable
Schema.UndefinedOr(s)T | undefinedOptional
Schema.NullishOr(s)T | null | undefinedNullish

Decoding Functions

FunctionReturnsThrows
Schema.decodeUnknownSync(s)(data)TypeParseError
Schema.decodeUnknownEither(s)(data)Either<Type, ParseError>Never
Schema.decodeUnknownOption(s)(data)Option<Type>Never
Schema.decodeUnknownPromise(s)(data)Promise<Type>On reject
Schema.decodeUnknown(s)(data)Effect<Type, ParseError>Never

Encoding Functions

FunctionReturnsThrows
Schema.encodeSync(s)(value)EncodedParseError
Schema.encodeEither(s)(value)Either<Encoded, ParseError>Never
Schema.encodeOption(s)(value)Option<Encoded>Never
Schema.encodePromise(s)(value)Promise<Encoded>On reject
Schema.encode(s)(value)Effect<Encoded, ParseError>Never

Validation Functions

FunctionReturnsDescription
Schema.is(s)(value)booleanType guard
Schema.asserts(s)(value)voidAssert or throw
Schema.validateSync(s)(value)TypeValidate Type

String Filters

FilterDescription
Schema.minLength(n)Minimum length
Schema.maxLength(n)Maximum length
Schema.length(n)Exact length
Schema.nonEmptyString()Non-empty
Schema.pattern(regex)Match pattern
Schema.startsWith(s)Starts with
Schema.endsWith(s)Ends with
Schema.includes(s)Contains
Schema.trimmed()No whitespace

Number Filters

FilterDescription
Schema.greaterThan(n)> n
Schema.greaterThanOrEqualTo(n)>= n
Schema.lessThan(n)< n
Schema.lessThanOrEqualTo(n)<= n
Schema.between(min, max)min <= x <= max
Schema.positive()> 0
Schema.negative()< 0
Schema.nonPositive()<= 0
Schema.nonNegative()>= 0
Schema.int()Integer
Schema.finite()Not NaN/Infinity
Schema.nonNaN()Not NaN
Schema.multipleOf(n)Divisible by n

Array Filters

FilterDescription
Schema.minItems(n)Minimum items
Schema.maxItems(n)Maximum items
Schema.itemsCount(n)Exact count

Transformations

Built-in

SchemaFromTo
Schema.NumberFromStringstringnumber
Schema.BooleanFromStringstringboolean
Schema.DateFromStringstringDate
Schema.BigIntstringbigint
Schema.BigIntFromNumbernumberbigint
Schema.Trimstringstring
Schema.Lowercasestringstring
Schema.Uppercasestringstring
Schema.split(sep)stringstring[]
Schema.parseJson(s)stringparsed

Custom

FunctionDescription
Schema.transform(from, to, options)Always-succeeding transform
Schema.transformOrFail(from, to, options)Can-fail transform
Schema.compose(a, b)Chain transformations

Struct Operations

FunctionDescription
Schema.pick(...keys)Select properties
Schema.omit(...keys)Remove properties
Schema.partial(s)Make all optional
Schema.required(s)Make all required
Schema.extend(s)Add properties
Schema.mutable(s)Remove readonly
Schema.rename(mapping)Rename properties

Property Signatures

FunctionDescription
Schema.optional(s)Optional property
Schema.optional(s, {default})With default
Schema.optional(s, {as: "Option"})As Option type
Schema.propertySignature(s)Custom signature
Schema.fromKey(key)Map from different key

Brands

FunctionDescription
Schema.brand(name)Add brand
Schema.fromBrand(constructor)From Brand constructor

Classes

FunctionDescription
Schema.Class<T>()(name, fields)Schema class
Schema.TaggedClass<T>()(tag, fields)Tagged class
Schema.TaggedError<T>()(tag, fields)Error class

Utilities

FunctionDescription
Schema.typeSchema(s)Extract Type schema
Schema.encodedSchema(s)Extract Encoded schema
Schema.keyof(s)Keys schema
Schema.format(s)Format as string
Schema.isSchema(x)Type guard

Parse Options

typescript
type ParseOptions = {
  errors?: "first" | "all"
  onExcessProperty?: "ignore" | "error" | "preserve"
  preserveKeyOrder?: boolean
}

Annotations

typescript
schema.annotations({
  identifier?: string
  title?: string
  description?: string
  examples?: T[]
  default?: T
  message?: (issue) => string
  jsonSchema?: object
  arbitrary?: (fc) => fc.Arbitrary<T>
  pretty?: (t) => string
  equivalence?: Equivalence<T>
})

Released under the MIT License.