import { Schema } from 'effect'
export class MyClass extends Schema.Class<MyClass>('MyClass')({
createdAt: Schema.Date,
}) {}
const rawData = { createdAt: new Date() }
// ParseError: Expected MyClass, actual {"createdAt":2025-02-03T11:14:58.181Z}
Schema.decodeUnknownSync(
Schema.typeSchema(MyClass),
)(rawData)
// No error, but result is not instanceof MyClass
Schema.decodeUnknownSync(
Schema.typeSchema(Schema.Struct({ ...MyClass.fields })),
)(rawData)
// No, error, and result is instanceof of MyClass
// but is there a better way to do this?
MyClass.make(
Schema.decodeUnknownSync(
Schema.typeSchema(Schema.Struct({ ...MyClass.fields })),
)(rawData),
)
import { Schema } from 'effect'
export class MyClass extends Schema.Class<MyClass>('MyClass')({
createdAt: Schema.Date,
}) {}
const rawData = { createdAt: new Date() }
// ParseError: Expected MyClass, actual {"createdAt":2025-02-03T11:14:58.181Z}
Schema.decodeUnknownSync(
Schema.typeSchema(MyClass),
)(rawData)
// No error, but result is not instanceof MyClass
Schema.decodeUnknownSync(
Schema.typeSchema(Schema.Struct({ ...MyClass.fields })),
)(rawData)
// No, error, and result is instanceof of MyClass
// but is there a better way to do this?
MyClass.make(
Schema.decodeUnknownSync(
Schema.typeSchema(Schema.Struct({ ...MyClass.fields })),
)(rawData),
)