Patch Changes
-
#4601
fad8cca
Thanks @gcanti! - Schema: enhance the internalformatUnknown
function 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
4296293
Thanks @gcanti! - Fix issue with generic filters when generating arbitraries, closes #4605.Previously, applying a
filter
to a schema when generating arbitraries could cause aTypeError
due 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
9c241ab
Thanks @gcanti! - Schema: simplifyStruct
andRecord
return types. -
#4591
082b0c1
Thanks @IMax153! - Improve clarity of theTimeoutException
error message -
#4604
be12983
Thanks @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
de88127
Thanks @gcanti! - Schema: exportField
type.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 }))