Skip to content

Added additionalProperties support to shape()#198

Merged
webdeveric merged 5 commits intomasterfrom
dev
Jul 5, 2025
Merged

Added additionalProperties support to shape()#198
webdeveric merged 5 commits intomasterfrom
dev

Conversation

@webdeveric
Copy link
Copy Markdown
Owner

No description provided.

@webdeveric webdeveric requested a review from Copilot July 5, 2025 17:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the shape() factory to optionally disallow extra properties and adds a helper (hasAdditionalProperties) plus tests to cover the new behavior.

  • Introduce additionalProperties boolean flag to shape(), defaulting to true
  • Implement hasAdditionalProperties utility and wire it into shape()
  • Update tests and type definitions around shape(), assume(), and add new tests for hasAdditionalProperties

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/predicate/factory/shape.ts Added additionalProperties parameter, hooked up extra-prop check
src/hasAdditionalProperties.ts New utility to detect unexpected object keys
src/index.ts Exported hasAdditionalProperties
test/predicate/factory/shape.test.ts Updated shape tests to cover nested object and new flag
test/hasAdditionalProperties.test.ts Added tests for array and object extra-property detection
test/predicate/factory/assume.test-d.ts Added TypeScript signature tests for assume()
test/predicate/assume.test.ts Basic runtime tests for assume()
bench/hasAdditionalProperties.bench.ts Benchmark for new utility
src/predicate/isUnknown.ts & isAny.ts Switched to use assume() for always-true predicates
src/predicate/factory/is.ts Fixed parameter naming in is() factory
Comments suppressed due to low confidence (3)

src/predicate/factory/shape.ts:44

  • Add JSDoc for the additionalProperties parameter on shape() to explain its effect and default value.
  additionalProperties = true,

src/predicate/factory/shape.ts:44

  • [nitpick] The parameter name additionalProperties can be ambiguous; consider renaming to allowAdditionalProperties to more clearly indicate its boolean semantics.
  additionalProperties = true,

test/predicate/factory/shape.test.ts:103

  • Add a test case for the default shape(userShape) (without passing false) to verify that extra properties are allowed by default, preserving backward compatibility.
  it('Can check for additional properties', () => {

@webdeveric webdeveric merged commit dec1c7b into master Jul 5, 2025
4 checks passed
@webdeveric webdeveric deleted the dev branch July 5, 2025 18:02
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 5, 2025

🎉 This PR is included in version 0.67.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants