diff --git a/ark/schema/structure/structure.ts b/ark/schema/structure/structure.ts index ca6b6951bf..3da68e8aca 100644 --- a/ark/schema/structure/structure.ts +++ b/ark/schema/structure/structure.ts @@ -336,7 +336,7 @@ const implementation: nodeImplementationOf = reduce: (inner, $) => { if (!inner.required && !inner.optional) return - const seen: Record = {} + const seen: Record = Object.create(null) let updated = false const newOptionalProps: OptionalNode[] = inner.optional ? [...inner.optional] : [] diff --git a/ark/type/__tests__/objects/props.test.ts b/ark/type/__tests__/objects/props.test.ts index 7455f56183..1618c816b9 100644 --- a/ark/type/__tests__/objects/props.test.ts +++ b/ark/type/__tests__/objects/props.test.ts @@ -94,4 +94,20 @@ contextualize(() => { }) ).throws(writeDuplicateKeyMessage("a")) }) + + it("allows prototype method names as keys", () => { + // constructor, hasOwnProperty, toString, etc. are valid object keys + // and should not be incorrectly flagged as duplicates + const T = type({ + constructor: "string", + hasOwnProperty: "number", + toString: "boolean" + }) + + attest<{ + constructor: string + hasOwnProperty: number + toString: boolean + }>(T.t) + }) })