import { DateTime, Option, Schema } from "effect";
const rootSchema = Schema.Struct({
d: Schema.Union([Schema.DateTimeUtcFromString, Schema.DateTimeUtcFromMillis]).pipe(
Schema.withConstructorDefault(() => Option.some(DateTime.nowUnsafe())),
)
}).pipe(Schema.encodeKeys({ d: "a" }));
Schema.decodeSync(rootSchema)({ a: "2024-01-01T00:00:00.000Z" }) // ✅ { d: DateTime }
Schema.encodeSync(rootSchema)({ d: DateTime.nowUnsafe() }) // ✅ { a: "2024-01-01T00:00:00.000Z" }
const childSchema = rootSchema.pipe(
Schema.fieldsAssign({
e: Schema.Int,
}), // some of the keys may need a different encoding name.
); // ❌ struct.mapFields is not a function
import { DateTime, Option, Schema } from "effect";
const rootSchema = Schema.Struct({
d: Schema.Union([Schema.DateTimeUtcFromString, Schema.DateTimeUtcFromMillis]).pipe(
Schema.withConstructorDefault(() => Option.some(DateTime.nowUnsafe())),
)
}).pipe(Schema.encodeKeys({ d: "a" }));
Schema.decodeSync(rootSchema)({ a: "2024-01-01T00:00:00.000Z" }) // ✅ { d: DateTime }
Schema.encodeSync(rootSchema)({ d: DateTime.nowUnsafe() }) // ✅ { a: "2024-01-01T00:00:00.000Z" }
const childSchema = rootSchema.pipe(
Schema.fieldsAssign({
e: Schema.Int,
}), // some of the keys may need a different encoding name.
); // ❌ struct.mapFields is not a function