Skip to content

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

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

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

Conversation

@nikelborm

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 behaviour 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

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 16, 2026
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f7f13e0

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

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator 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 v4 fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error' v4 fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error' Jul 16, 2026
@IMax153
IMax153 requested a review from gcanti July 16, 2026 19:51
@IMax153 IMax153 added the 4.0 label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants