fix: allow prototype method names as object keys#1586
Merged
ssalbdivad merged 1 commit intoJul 7, 2026
Conversation
Object.prototype method names like 'constructor', 'hasOwnProperty',
and 'toString' are valid object keys and should not be incorrectly
flagged as duplicate keys.
The issue was that the 'seen' object used for duplicate detection was
initialized with '{}' which has prototype methods. When checking
'key in seen' for these keys, it returned true even though they
weren't explicitly set.
Fix: Use Object.create(null) to create a prototype-free object for
the 'seen' tracking.
Fixes arktypeio#1572
Contributor
|
Leaping into action... |
Member
|
sorry for the delay merging this, good find! |
ssalbdivad
added a commit
that referenced
this pull request
Jul 7, 2026
Bumps all publishable packages and documents the fixes merged since 2.2.2: - fix type.fn.raw throwing at runtime (#1631, @aarsh767) - anchor versioned UUID validation (#1602, @WolfieLeader) - fix inferred output of declared morphs (#1579, @eralmansouri) - allow Object.prototype method names as keys (#1586, @kaigritun) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qk4c4vPUecBDYbd4p3yE1H
ssalbdivad
added a commit
that referenced
this pull request
Jul 7, 2026
Bumps all publishable packages and documents the fixes merged since 2.2.2: - fix type.fn.raw throwing at runtime (#1631, @aarsh767) - anchor versioned UUID validation (#1602, @WolfieLeader) - fix inferred output of declared morphs (#1579, @eralmansouri) - allow Object.prototype method names as keys (#1586, @kaigritun)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #1572
Object.prototype method names like
constructor,hasOwnProperty, andtoStringare valid object keys and should not be incorrectly flagged as duplicate keys.Problem
When defining an object type with a key that matches an
Object.prototypemethod name:This throws a
ParseError: Duplicate key "constructor"even though the key is valid.Root Cause
The
seenobject used for duplicate key detection was initialized with{}, which inherits fromObject.prototype. When checkingkey in seen, it returnedtruefor keys like"constructor"because they exist on the prototype chain.Solution
Use
Object.create(null)to create a prototype-free object for theseentracking. This ensures only explicitly set keys are detected as duplicates.Testing
Added a test case to verify that prototype method names can be used as object keys without error.