effect@3.13.11
Patch Changes
-
#4601
fad8ccaThanks @gcanti! - Schema: enhance the internalformatUnknownfunction to handle various types including iterables, classes, and additional edge cases.Before
import { Schema } from "effect" const schema = Schema.Array(Schema.Number) Schema.decodeUnknownSync(schema)(new Set([1, 2])) // throws Expected ReadonlyArray<number>, actual {} class A { constructor(readonly a: number) {} } Schema.decodeUnknownSync(schema)(new A(1)) // throws Expected ReadonlyArray<number>, actual {"a":1}
After
import { Schema } from "effect" const schema = Schema.Array(Schema.Number) Schema.decodeUnknownSync(schema)(new Set([1, 2])) // throws Expected ReadonlyArray<number>, actual Set([1,2]) class A { constructor(readonly a: number) {} } Schema.decodeUnknownSync(schema)(new A(1)) // throws Expected ReadonlyArray<number>, actual A({"a":1})
-
#4606
4296293Thanks @gcanti! - Fix issue with generic filters when generating arbitraries, closes #4605.Previously, applying a
filterto a schema when generating arbitraries could cause aTypeErrordue to missing properties. This fix ensures that arbitraries are generated correctly when filters are used.Before
import { Arbitrary, Schema } from "effect" const schema = Schema.BigIntFromSelf.pipe(Schema.filter(() => true)) Arbitrary.make(schema) // TypeError: Cannot read properties of undefined (reading 'min')
After
import { Arbitrary, Schema } from "effect" const schema = Schema.BigIntFromSelf.pipe(Schema.filter(() => true)) const result = Arbitrary.make(schema) // Works correctly
-
#4587
9c241abThanks @gcanti! - Schema: simplifyStructandRecordreturn types. -
#4591
082b0c1Thanks @IMax153! - Improve clarity of theTimeoutExceptionerror message -
#4604
be12983Thanks @gcanti! - Add support for refinements toSchema.omit, closes #4603.Before
import { Schema } from "effect" const schema = Schema.Struct({ a: Schema.String, b: Schema.String }) const omitted = schema.pipe( Schema.filter(() => true), Schema.omit("a") ) console.log(String(omitted.ast)) // {} ❌
After
import { Schema } from "effect" const schema = Schema.Struct({ a: Schema.String, b: Schema.String }) const omitted = schema.pipe( Schema.filter(() => true), Schema.omit("a") ) console.log(String(omitted.ast)) // { readonly b: string }
-
#4593
de88127Thanks @gcanti! - Schema: exportFieldtype.Useful for creating a type that can be used to add custom constraints to the fields of a struct.
import { Schema } from "effect" const f = <Fields extends Record<"a" | "b", Schema.Struct.Field>>( schema: Schema.Struct<Fields> ) => { return schema.omit("a") } // ┌─── Schema.Struct<{ b: typeof Schema.Number; }> // ▼ const result = f(Schema.Struct({ a: Schema.String, b: Schema.Number }))