Skip to content

fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preseve' | 'error'#6298

Open
nikelborm wants to merge 1 commit into
Effect-TS:mainfrom
nikelborm:schema-struct-empty-fields
Open

fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preseve' | 'error'#6298
nikelborm wants to merge 1 commit into
Effect-TS:mainfrom
nikelborm:schema-struct-empty-fields

Conversation

@nikelborm

@nikelborm nikelborm commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Motivation: you remove one field in the schema; the decoded object gets fewer fields. You remove another; fewer again. You remove the last; suddenly, all the fields come back, regardless of the default onExcessProperty: "ignore". If the user wants to retrieve all fields, they can set onExcessProperty: "preserve".

I tried to defend old behavior with "{} means typeof obj === 'object' && obj !== null and effect's schema tries to be closer to TypeScript's behaviour, by treating Schema.Struct({}) as something passing the condition". And this might hold in isolation. But considering the context, by this logic, any fields which are not explicitly mentioned in Schema.Struct({ ... }) should be preserved in all decoded objects, not only the ones that have {} signature, to follow TypeScript's assignability rules. And this is not what happens. The behavior should be consistent between field-less and field-ful structs.

Related

@nikelborm nikelborm requested a review from gcanti as a code owner June 29, 2026 14:23
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jun 29, 2026
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9feabbb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
effect Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

1 participant