Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
struct should allow a "constructor" field name
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jun 30, 2023
1 parent d57c92f commit 060ce80
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/funny-grapes-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

struct should allow a "constructor" field name
2 changes: 1 addition & 1 deletion src/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ export const createTypeLiteral = (
const keys: Record<PropertyKey, null> = {}
for (let i = 0; i < propertySignatures.length; i++) {
const name = propertySignatures[i].name
if (name in keys) {
if (Object.prototype.hasOwnProperty.call(keys, name)) {
throw new Error(`Duplicate property signature ${String(name)}`)
}
keys[name] = null
Expand Down
5 changes: 5 additions & 0 deletions test/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ describe.concurrent("Schema", () => {
expect(S.clampBigint).exist
})

it("struct should allow a \"constructor\" field name", () => {
const schema = S.struct({ constructor: S.string })
expect(schema.ast._tag).toEqual("TypeLiteral")
})

it("brand/ annotations", () => {
// const Branded: S.Schema<number & Brand<"A"> & Brand<"B">>
const Branded = pipe(
Expand Down

0 comments on commit 060ce80

Please sign in to comment.