github Effect-TS/effect @effect/schema@0.67.2

latest releases: @effect/vitest@0.10.5, @effect/sql-sqlite-wasm@0.13.0, @effect/sql-sqlite-react-native@0.16.0...
4 months ago

Patch Changes

  • #2738 89a3afb Thanks @gcanti! - add cause in errors thrown by asserts, closes #2729

  • #2741 992c8e2 Thanks @gcanti! - Schema.optional: the default option now allows setting a default value for both the decoding phase and the default constructor. Previously, it only set the decoding default. Closes #2740.

    Example

    import { Schema } from "@effect/schema";
    
    const Product = Schema.Struct({
      name: Schema.String,
      price: Schema.NumberFromString,
      quantity: Schema.optional(Schema.NumberFromString, { default: () => 1 }),
    });
    
    // Applying defaults in the decoding phase
    console.log(
      Schema.decodeUnknownSync(Product)({ name: "Laptop", price: "999" }),
    ); // { name: 'Laptop', price: 999, quantity: 1 }
    console.log(
      Schema.decodeUnknownSync(Product)({
        name: "Laptop",
        price: "999",
        quantity: "2",
      }),
    ); // { name: 'Laptop', price: 999, quantity: 2 }
    
    // Applying defaults in the constructor
    console.log(Product.make({ name: "Laptop", price: 999 })); // { name: 'Laptop', price: 999, quantity: 1 }
    console.log(Product.make({ name: "Laptop", price: 999, quantity: 2 })); // { name: 'Laptop', price: 999, quantity: 2 }

Don't miss a new effect release

NewReleases is sending notifications on new releases.