Skip to content

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

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

v3 fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error'#6298
nikelborm wants to merge 1 commit into
Effect-TS:v3from
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: b32a8a3

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

@nikelborm nikelborm changed the title fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preseve' | 'error' fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error' Jul 4, 2026
@nikelborm
nikelborm force-pushed the schema-struct-empty-fields branch from 9feabbb to b32a8a3 Compare July 4, 2026 20:58
@IMax153
IMax153 changed the base branch from main to v3 July 13, 2026 23:55
@IMax153 IMax153 added the 3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3. label Jul 14, 2026
@nikelborm nikelborm changed the title fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error' v3 fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error' Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3.

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants