Skip to content

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

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

fix: Made field-less Schema.Struct({}) respect onExcessProperty: 'ignore' | 'preserve' | 'error'#2503
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

@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3c65513

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 force-pushed the schema-struct-empty-fields branch 5 times, most recently from 8c6e994 to 65d6a19 Compare July 4, 2026 20:24
@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 2 times, most recently from be3e7f5 to f570b28 Compare July 4, 2026 20:44
@nikelborm nikelborm force-pushed the schema-struct-empty-fields branch from f570b28 to 3c65513 Compare July 4, 2026 20:57
@IMax153

IMax153 commented Jul 14, 2026

Copy link
Copy Markdown
Member

Hi @nikelborm,

The Effect V4 codebase has been merged back into Effect-TS/effect, where V4 development now continues on the main branch.

GitHub cannot transfer pull requests between repositories. If you would like to continue this contribution, please open a replacement pull request against Effect-TS/effect:main and include a link to this PR for its existing discussion and review history.

After opening the replacement, please reply here with its URL so maintainers can verify the migration and close this source PR.

@nikelborm

Copy link
Copy Markdown
Contributor Author

I had a mirror PR opened against v3 Effect-TS/effect#6298

Should I close it and create a new one, or should I overwrite the changes in that one?

@IMax153

IMax153 commented Jul 14, 2026

Copy link
Copy Markdown
Member

@nikelborm - the Effect v3 codebase still lives on the v3 branch - all PRs (including yours) that were opened prior to the v4 codebase merger have been re-targeted to the v3 branch.

So I would suggest opening a companion PR targeting main (i.e. the v4 codebase).

@fubhy fubhy closed this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants