effect@3.13.3
Patch Changes
-
#4502
cc5588dThanks @gcanti! - Schema: More Accurate Return Types forDataFromSelfandData.This update refines the return types of
DataFromSelfandData, 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
623c8cdThanks @gcanti! - Schema: More Accurate Return Type forcompose.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
00b4eb1Thanks @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:
maxLengthminLengthlengthpatternstartsWithendsWithincludeslowercasedcapitalizeduncapitalizeduppercasednonEmptyStringtrimmed
Number filters:
finitegreaterThangreaterThanOrEqualTolessThanlessThanOrEqualTointmultipleOfbetweennonNaNpositivenegativenonPositivenonNegative
BigInt filters:
greaterThanBigIntgreaterThanOrEqualToBigIntlessThanBigIntlessThanOrEqualToBigIntbetweenBigIntpositiveBigIntnegativeBigIntnonNegativeBigIntnonPositiveBigInt
Duration filters:
lessThanDurationlessThanOrEqualToDurationgreaterThanDurationgreaterThanOrEqualToDurationbetweenDuration
Array filters:
minItemsmaxItemsitemsCount
Date filters:
validDatelessThanDatelessThanOrEqualToDategreaterThanDategreaterThanOrEqualToDatebetweenDate
BigDecimal filters:
greaterThanBigDecimalgreaterThanOrEqualToBigDecimallessThanBigDecimallessThanOrEqualToBigDecimalpositiveBigDecimalnonNegativeBigDecimalnegativeBigDecimalnonPositiveBigDecimalbetweenBigDecimal
-
#4508
f2aee98Thanks @gcanti! - Schema: More Accurate Return Types forArrayEnsureandNonEmptyArrayEnsure.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
fb798ebThanks @gcanti! - Schema: More Accurate Return Types for:transformLiteralclampclampBigIntclampDurationclampBigDecimalheadheadNonEmptyheadOrElse
-
#4524
2251b15Thanks @gcanti! - Schema: More Accurate Return Type forparseNumber.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
2e15c1eThanks @mikearnaldi! - Fix nested batching -
#4514
a4979dbThanks @gcanti! - Schema: add missingfromproperty tobrandinterface.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
b74255aThanks @tim-smart! - ensure fibers can't be added to Fiber{Handle,Set,Map} during closing -
#4419
d7f6a5cThanks @KhraksMamtsov! - Fix Context.Tag unification -
#4495
9dd8979Thanks @KhraksMamtsov! - SimplifysortWith,sort,reverse,sortBy,unzip,dedupesignatures in Array module -
#4507
477b488Thanks @gcanti! - Schema: More Accurate Return Type forparseJson(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
10932cbThanks @gcanti! - RefactorJSONSchemato useadditionalPropertiesinstead ofpatternPropertiesfor simple records, closes #4518.This update improves how records are represented in JSON Schema by replacing
patternPropertieswithadditionalProperties, 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 withpatternProperties, generatingRecord<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,
additionalPropertiesis 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" } } */
- Fixes OpenAPI issues – Previously, records were represented using
-
#4501
9f6c784Thanks @gcanti! - Schema: Add MissingdeclareAPI Interface to Expose Type Parameters.Example
import { Schema } from "effect" const schema = Schema.OptionFromSelf(Schema.String) // ┌─── readonly [typeof Schema.String] // ▼ schema.typeParameters
-
#4487
2c639ecThanks @gcanti! - Schema: more precise return types when transformations are involved.ChunkNonEmptyChunkRedactedOptionOptionFromNullOrOptionFromUndefinedOrOptionFromNullishOrEitherEitherFromUnionReadonlyMapMapHashMapReadonlySetSetHashSetListCauseExitSortedSetheadheadNonEmptyheadOrElse
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
886aaa8Thanks @gcanti! - Schema: ImproveLiteralreturn type — now returnsSchemaClassinstead ofSchema