Patch Changes
-
#4502
cc5588d
Thanks @gcanti! - Schema: More Accurate Return Types forDataFromSelf
andData
.This update refines the return types of
DataFromSelf
andData
, 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 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
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 forArrayEnsure
andNonEmptyArrayEnsure
.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 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
2e15c1e
Thanks @mikearnaldi! - Fix nested batching -
#4514
a4979db
Thanks @gcanti! - Schema: add missingfrom
property tobrand
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! - SimplifysortWith
,sort
,reverse
,sortBy
,unzip
,dedupe
signatures in Array module -
#4507
477b488
Thanks @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
10932cb
Thanks @gcanti! - RefactorJSONSchema
to useadditionalProperties
instead ofpatternProperties
for simple records, closes #4518.This update improves how records are represented in JSON Schema by replacing
patternProperties
withadditionalProperties
, 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,
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" } } */
- Fixes OpenAPI issues – Previously, records were represented using
-
#4501
9f6c784
Thanks @gcanti! - Schema: Add Missingdeclare
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: ImproveLiteral
return type — now returnsSchemaClass
instead ofSchema