Effect-TS/schema

Arbitrary not working for Classes

Closed this issue ยท 2 comments

๐Ÿ› Bug report

Current Behavior

When creating an Arbitrary with Classes schemas, the generated To type is an empty object {}

Expected behavior

The generated object should be an instance of the class

Reproducible example

import * as A from "@effect/schema/Arbitrary"
import * as S from "@effect/schema/Schema"
import * as fc from "fast-check"

class Person extends S.Class()({
    name: S.string
}) {}
const arbitrary = A.to(Person)
const generated = fc.sample(arbitrary(fc))[0]
console.log(generated) // {}

Suggested solution(s)

Not really familiar with the codebase but, it seems to be related with the AST of the Class schema

Additional context

To highlight this issue, I have replicated struct tests for classes, they are currently failing: https://github.com/wewelll/schema/pull/1/files

Your environment

Software Version(s)
@effect/schema 0.36.0
TypeScript 5.2.2
gcanti commented

Thanks @wewelll , patch released

Thank you @gcanti !