Patch Changes
-
#2582
b3fe829
Thanks @gcanti! - Add default title annotations to both sides of Struct transformations.This simple addition helps make error messages shorter and more understandable.
Before
import { Schema } from "@effect/schema"; const schema = Schema.Struct({ a: Schema.optional(Schema.String, { exact: true, default: () => "" }), b: Schema.String, c: Schema.String, d: Schema.String, e: Schema.String, f: Schema.String, }); Schema.decodeUnknownSync(schema)({ a: 1 }); /* throws Error: ({ a?: string; b: string; c: string; d: string; e: string; f: string } <-> { a: string; b: string; c: string; d: string; e: string; f: string }) └─ Encoded side transformation failure └─ { a?: string; b: string; c: string; d: string; e: string; f: string } └─ ["a"] └─ Expected a string, actual 1 */
Now
import { Schema } from "@effect/schema"; const schema = Schema.Struct({ a: Schema.optional(Schema.String, { exact: true, default: () => "" }), b: Schema.String, c: Schema.String, d: Schema.String, e: Schema.String, f: Schema.String, }); Schema.decodeUnknownSync(schema)({ a: 1 }); /* throws Error: (Struct (Encoded side) <-> Struct (Type side)) └─ Encoded side transformation failure └─ Struct (Encoded side) └─ ["a"] └─ Expected a string, actual 1 */
-
#2581
a58b7de
Thanks @gcanti! - Fix formatting for Class and brands AST. -
#2579
d90e8c3
Thanks @gcanti! - Schema: JSONSchema should support make(Class)Before
import { JSONSchema, Schema } from "@effect/schema"; class A extends Schema.Class<A>("A")({ a: Schema.String, }) {} console.log(JSONSchema.make(A)); // throws MissingAnnotation: cannot build a JSON Schema for a declaration without a JSON Schema annotation
Now
console.log(JSONSchema.make(A)); /* Output: { '$schema': 'http://json-schema.org/draft-07/schema#', type: 'object', required: [ 'a' ], properties: { a: { type: 'string', description: 'a string', title: 'string' } }, additionalProperties: false } */