Patch Changes
-
#2141
dbff62c
Thanks @gcanti! - add{ exact: true }
optional argument to thepartial
API, mirroring the implementation in theoptional
API, closes #2140The
partial
operation allows you to make all properties within a schema optional.By default, the
partial
operation adds a union withundefined
to the types. If you wish to avoid this, you can opt-out by passing a{ exact: true }
argument to thepartial
operation.Example
import * as S from "@effect/schema/Schema"; /* const schema: S.Schema<{ readonly a?: string | undefined; }, { readonly a?: string | undefined; }, never> */ const schema = S.partial(S.struct({ a: S.string })); S.decodeUnknownSync(schema)({ a: "a" }); // ok S.decodeUnknownSync(schema)({ a: undefined }); // ok /* const exact: S.Schema<{ readonly a?: string; }, { readonly a?: string; }, never> */ const exactSchema = S.partial(S.struct({ a: S.string }), { exact: true }); S.decodeUnknownSync(exactSchema)({ a: "a" }); // ok S.decodeUnknownSync(exactSchema)({ a: undefined }); /* throws: Error: { a?: string } └─ ["a"] └─ Expected a string, actual undefined */
-
#2128
e572b07
Thanks @tim-smart! - allow passing structs when encoding schema classesThe following will no longer throw an error:
import * as S from "@effect/schema/Schema"; class C extends S.Class<C>()({ n: S.NumberFromString, }) { get b() { return 1; } } class D extends S.Class<D>()({ n: S.NumberFromString, b: S.number, }) {} console.log(S.encodeSync(D)(new C({ n: 1 }))); // Output: { b: 1, n: '1' }
-
#2123
e787a57
Thanks @gcanti! - Refactor thedeclare
signature to ensure that the decoding and encoding functions do not utilize context.As a result, we can relax the signature of the following functions to accept
R !== never
:Parser.validateSync
Parser.validateOption
Parser.validateEither
Parser.is
Parser.asserts
Schema.validateSync
Schema.validateOption
Schema.validateEither
Schema.is
Schema.asserts
Additionally, the
Class
API no longer requires the optional argumentdisableValidation
to betrue
whenR !== never
. -
Updated dependencies [
b1163b2
,b46b869
,de1b226
,a663390
,ff88f80
,11be07b
,c568645
,88835e5
,b415577
,ff8046f
]:- effect@2.3.6