Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
fix missing class .struct schema (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Nov 21, 2023
1 parent 36c9573 commit 4491e75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/swift-cameras-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

fix missing class .struct schema
2 changes: 2 additions & 0 deletions src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3789,6 +3789,8 @@ const makeClass = <I, A>(
).ast
}

static struct = selfSchema

static extend() {
return (fields: any) => {
const newFields = { ...selfFields, ...fields }
Expand Down
7 changes: 6 additions & 1 deletion test/Schema/Class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Data from "effect/Data"
import * as Equal from "effect/Equal"
import * as O from "effect/Option"
import * as Request from "effect/Request"
import { describe, expect, it } from "vitest"
import { assert, describe, expect, it } from "vitest"

class Person extends S.Class<Person>()({
id: S.number,
Expand Down Expand Up @@ -129,6 +129,11 @@ describe("Schema/Class", () => {
)
})

it(".struct", async () => {
const person = S.parseSync(Person.struct)({ id: 1, name: "John" })
assert.deepStrictEqual(person, { id: 1, name: "John" })
})

it("extends", () => {
const person = S.parseSync(PersonWithAge)({
id: 1,
Expand Down

0 comments on commit 4491e75

Please sign in to comment.