github Effect-TS/effect effect@3.13.3

latest releases: @effect/sql-sqlite-bun@0.31.4, @effect/vitest@0.19.2, @effect/platform-browser@0.56.4...
one day ago

Patch Changes

  • #4502 cc5588d Thanks @gcanti! - Schema: More Accurate Return Types for DataFromSelf and Data.

    This update refines the return types of DataFromSelf and Data, making them clearer and more specific, especially when working with structured schemas.

    Before

    The return types were more generic, making it harder to see the underlying structure:

    import { Schema } from "effect"
    
    const struct = Schema.Struct({ a: Schema.NumberFromString })
    
    //       ┌─── Schema.DataFromSelf<Schema<{ readonly a: number; }, { readonly a: string; }>>
    //       ▼
    const schema1 = Schema.DataFromSelf(struct)
    
    //       ┌─── Schema.Data<Schema<{ readonly a: number; }, { readonly a: string; }>>
    //       ▼
    const schema2 = Schema.Data(struct)

    After

    Now, the return types clearly reflect the original schema structure:

    import { Schema } from "effect"
    
    const struct = Schema.Struct({ a: Schema.NumberFromString })
    
    //       ┌─── Schema.DataFromSelf<Schema.Struct<{ a: typeof Schema.NumberFromString; }>>
    //       ▼
    const schema1 = Schema.DataFromSelf(struct)
    
    //       ┌─── Schema.Data<Schema.Struct<{ a: typeof Schema.NumberFromString; }>>
    //       ▼
    const schema2 = Schema.Data(struct)
  • #4510 623c8cd Thanks @gcanti! - Schema: More Accurate Return Type for compose.

    Before

    import { Schema } from "effect"
    
    //      ┌─── SchemaClass<number | null, string>
    //      ▼
    const schema = Schema.compose(
      Schema.NumberFromString,
      Schema.NullOr(Schema.Number)
    )
    
    // @ts-expect-error: Property 'from' does not exist
    schema.from
    
    // @ts-expect-error: Property 'to' does not exist
    schema.to

    After

    import { Schema } from "effect"
    
    //      ┌─── transform<typeof Schema.NumberFromString, Schema.NullOr<typeof Schema.Number>>
    //      ▼
    const schema = Schema.compose(
      Schema.NumberFromString,
      Schema.NullOr(Schema.Number)
    )
    
    //      ┌─── typeof Schema.NumberFromString
    //      ▼
    schema.from
    
    //      ┌─── Schema.NullOr<typeof Schema.Number>
    //      ▼
    schema.to
  • #4488 00b4eb1 Thanks @gcanti! - Schema: more precise return types when filters are involved.

    Example (with Schema.maxLength)

    Before

    import { Schema } from "effect"
    
    //      ┌─── Schema.filter<Schema.Schema<string, string, never>>
    //      ▼
    const schema = Schema.String.pipe(Schema.maxLength(10))
    
    // Schema<string, string, never>
    schema.from

    After

    import { Schema } from "effect"
    
    //      ┌─── Schema.filter<typeof Schema.String>
    //      ▼
    const schema = Schema.String.pipe(Schema.maxLength(10))
    
    // typeof Schema.String
    schema.from

    String filters:

    • maxLength
    • minLength
    • length
    • pattern
    • startsWith
    • endsWith
    • includes
    • lowercased
    • capitalized
    • uncapitalized
    • uppercased
    • nonEmptyString
    • trimmed

    Number filters:

    • finite
    • greaterThan
    • greaterThanOrEqualTo
    • lessThan
    • lessThanOrEqualTo
    • int
    • multipleOf
    • between
    • nonNaN
    • positive
    • negative
    • nonPositive
    • nonNegative

    BigInt filters:

    • greaterThanBigInt
    • greaterThanOrEqualToBigInt
    • lessThanBigInt
    • lessThanOrEqualToBigInt
    • betweenBigInt
    • positiveBigInt
    • negativeBigInt
    • nonNegativeBigInt
    • nonPositiveBigInt

    Duration filters:

    • lessThanDuration
    • lessThanOrEqualToDuration
    • greaterThanDuration
    • greaterThanOrEqualToDuration
    • betweenDuration

    Array filters:

    • minItems
    • maxItems
    • itemsCount

    Date filters:

    • validDate
    • lessThanDate
    • lessThanOrEqualToDate
    • greaterThanDate
    • greaterThanOrEqualToDate
    • betweenDate

    BigDecimal filters:

    • greaterThanBigDecimal
    • greaterThanOrEqualToBigDecimal
    • lessThanBigDecimal
    • lessThanOrEqualToBigDecimal
    • positiveBigDecimal
    • nonNegativeBigDecimal
    • negativeBigDecimal
    • nonPositiveBigDecimal
    • betweenBigDecimal
  • #4508 f2aee98 Thanks @gcanti! - Schema: More Accurate Return Types for ArrayEnsure and NonEmptyArrayEnsure.

    Before

    import { Schema } from "effect"
    
    const schema1 = Schema.ArrayEnsure(Schema.String)
    
    // @ts-expect-error: Property 'from' does not exist
    schema1.from
    
    const schema2 = Schema.NonEmptyArrayEnsure(Schema.String)
    
    // @ts-expect-error: Property 'from' does not exist
    schema2.from

    After

    import { Schema } from "effect"
    
    const schema1 = Schema.ArrayEnsure(Schema.String)
    
    //        ┌─── Schema.Union<[typeof Schema.String, Schema.Array$<typeof Schema.String>]>
    //        ▼
    schema1.from
    
    const schema2 = Schema.NonEmptyArrayEnsure(Schema.String)
    
    //        ┌─── Schema.Union<[typeof Schema.String, Schema.NonEmptyArray<typeof Schema.String>]>
    //        ▼
    schema2.from
  • #4509 fb798eb Thanks @gcanti! - Schema: More Accurate Return Types for:

    • transformLiteral
    • clamp
    • clampBigInt
    • clampDuration
    • clampBigDecimal
    • head
    • headNonEmpty
    • headOrElse
  • #4524 2251b15 Thanks @gcanti! - Schema: More Accurate Return Type for parseNumber.

    Before

    import { Schema } from "effect"
    
    const schema = Schema.parseNumber(Schema.String)
    
    //      ┌─── Schema<string>
    //      ▼
    schema.from

    After

    import { Schema } from "effect"
    
    const schema = Schema.parseNumber(Schema.String)
    
    //      ┌─── typeof Schema.String
    //      ▼
    schema.from
  • #4483 2e15c1e Thanks @mikearnaldi! - Fix nested batching

  • #4514 a4979db Thanks @gcanti! - Schema: add missing from property to brand interface.

    Before

    import { Schema } from "effect"
    
    const schema = Schema.String.pipe(Schema.brand("my-brand"))
    
    // @ts-expect-error: Property 'from' does not exist
    schema.from

    After

    import { Schema } from "effect"
    
    const schema = Schema.String.pipe(Schema.brand("my-brand"))
    
    //      ┌─── typeof Schema.String
    //      ▼
    schema.from
  • #4496 b74255a Thanks @tim-smart! - ensure fibers can't be added to Fiber{Handle,Set,Map} during closing

  • #4419 d7f6a5c Thanks @KhraksMamtsov! - Fix Context.Tag unification

  • #4495 9dd8979 Thanks @KhraksMamtsov! - Simplify sortWith, sort, reverse, sortBy, unzip, dedupe signatures in Array module

  • #4507 477b488 Thanks @gcanti! - Schema: More Accurate Return Type for parseJson(schema).

    Before

    import { Schema } from "effect"
    
    //      ┌─── Schema.SchemaClass<{ readonly a: number; }, string>
    //      ▼
    const schema = Schema.parseJson(
      Schema.Struct({
        a: Schema.NumberFromString
      })
    )
    
    // @ts-expect-error: Property 'to' does not exist
    schema.to

    After

    import { Schema } from "effect"
    
    //      ┌─── Schema.transform<Schema.SchemaClass<unknown, string, never>, Schema.Struct<{ a: typeof Schema.NumberFromString; }>>
    //      ▼
    const schema = Schema.parseJson(
      Schema.Struct({
        a: Schema.NumberFromString
      })
    )
    
    //      ┌─── Schema.Struct<{ a: typeof Schema.NumberFromString; }>
    //      ▼
    schema.to
  • #4519 10932cb Thanks @gcanti! - Refactor JSONSchema to use additionalProperties instead of patternProperties for simple records, closes #4518.

    This update improves how records are represented in JSON Schema by replacing patternProperties with additionalProperties, resolving issues in OpenAPI schema generation.

    Why the change?

    • Fixes OpenAPI issues – Previously, records were represented using patternProperties, which caused problems with OpenAPI tools.
    • Better schema compatibility – Some tools, like openapi-ts, struggled with patternProperties, generating Record<string, never> instead of the correct type.
    • Fixes missing example values – When using patternProperties, OpenAPI failed to generate proper response examples, displaying only {}.
    • Simplifies schema modification – Users previously had to manually fix schemas with OpenApi.Transform, which was messy and lacked type safety.

    Before

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Record({ key: Schema.String, value: Schema.Number })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": [],
      "properties": {},
      "patternProperties": {
        "": { // ❌ Empty string pattern
          "type": "number"
        }
      }
    }
    */

    After

    Now, additionalProperties is used instead, which properly represents an open-ended record:

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Record({ key: Schema.String, value: Schema.Number })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": [],
      "properties": {},
      "additionalProperties": { // ✅ Represents unrestricted record keys
        "type": "number"
      }
    }
    */
  • #4501 9f6c784 Thanks @gcanti! - Schema: Add Missing declare API Interface to Expose Type Parameters.

    Example

    import { Schema } from "effect"
    
    const schema = Schema.OptionFromSelf(Schema.String)
    
    //       ┌─── readonly [typeof Schema.String]
    //       ▼
    schema.typeParameters
  • #4487 2c639ec Thanks @gcanti! - Schema: more precise return types when transformations are involved.

    • Chunk
    • NonEmptyChunk
    • Redacted
    • Option
    • OptionFromNullOr
    • OptionFromUndefinedOr
    • OptionFromNullishOr
    • Either
    • EitherFromUnion
    • ReadonlyMap
    • Map
    • HashMap
    • ReadonlySet
    • Set
    • HashSet
    • List
    • Cause
    • Exit
    • SortedSet
    • head
    • headNonEmpty
    • headOrElse

    Example (with Schema.Chunk)

    Before

    import { Schema } from "effect"
    
    const schema = Schema.Chunk(Schema.Number)
    
    // Property 'from' does not exist on type 'Chunk<typeof Number$>'
    schema.from

    After

    import { Schema } from "effect"
    
    const schema = Schema.Chunk(Schema.Number)
    
    // Schema.Array$<typeof Schema.Number>
    schema.from
  • #4492 886aaa8 Thanks @gcanti! - Schema: Improve Literal return type — now returns SchemaClass instead of Schema

Don't miss a new effect release

NewReleases is sending notifications on new releases.