Skip to content

fix(schema): preserve named-field decoded value on StructWithRest key overlap#2246

Closed
Leka74 wants to merge 1 commit into
Effect-TS:mainfrom
Leka74:fix/structwithrest-shadow
Closed

fix(schema): preserve named-field decoded value on StructWithRest key overlap#2246
Leka74 wants to merge 1 commit into
Effect-TS:mainfrom
Leka74:fix/structwithrest-shadow

Conversation

@Leka74
Copy link
Copy Markdown
Contributor

@Leka74 Leka74 commented May 20, 2026

Type

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

Description

When a Schema.StructWithRest index signature's key domain overlapped a named property signature, the index signature's decoded value overwrote the property signature's transformed value. The declared type narrowed via intersection but the runtime did not.

const S = Schema.StructWithRest(
  Schema.Struct({ count: Schema.NumberFromString }),
  [Schema.Record(Schema.String, Schema.Unknown)]
)

Schema.decodeUnknownSync(S)({ count: "42" })
// before: { count: "42" }  (raw string)
// after:  { count: 42 }    (transformed number)

The index signature still runs for overlapping keys, its refinement checks (e.g. Schema.Finite) still apply and surface errors but its decoded value is no longer written when a property signature has already produced one.

disclaimer: fix applied with Opus 4.7

Related

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

🦋 Changeset detected

Latest commit: fc1cdb9

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

@gcanti
Copy link
Copy Markdown
Contributor

gcanti commented Jun 1, 2026

Closing in favor of #2312

@gcanti gcanti closed this Jun 1, 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.

StructWithRest: index signatures shadow named-field decoders at runtime

2 participants