From 4491e75e07db07944e8fda9fa08d3ef0ca1a56d1 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 21 Nov 2023 14:13:13 +1300 Subject: [PATCH] fix missing class .struct schema (#580) --- .changeset/swift-cameras-join.md | 5 +++++ src/Schema.ts | 2 ++ test/Schema/Class.test.ts | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/swift-cameras-join.md diff --git a/.changeset/swift-cameras-join.md b/.changeset/swift-cameras-join.md new file mode 100644 index 000000000..436a4270a --- /dev/null +++ b/.changeset/swift-cameras-join.md @@ -0,0 +1,5 @@ +--- +"@effect/schema": patch +--- + +fix missing class .struct schema diff --git a/src/Schema.ts b/src/Schema.ts index 43c44589f..f2548cf38 100644 --- a/src/Schema.ts +++ b/src/Schema.ts @@ -3789,6 +3789,8 @@ const makeClass = ( ).ast } + static struct = selfSchema + static extend() { return (fields: any) => { const newFields = { ...selfFields, ...fields } diff --git a/test/Schema/Class.test.ts b/test/Schema/Class.test.ts index 302967a00..4d0030876 100644 --- a/test/Schema/Class.test.ts +++ b/test/Schema/Class.test.ts @@ -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()({ id: S.number, @@ -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,