Skip to content

Fix use of Schema.NonEmptyArrayEnsure with strings - #7170

Open
thewilkybarkid wants to merge 1 commit into
Effect-TS:v3from
thewilkybarkid:non-empty-array-ensure-strings
Open

Fix use of Schema.NonEmptyArrayEnsure with strings#7170
thewilkybarkid wants to merge 1 commit into
Effect-TS:v3from
thewilkybarkid:non-empty-array-ensure-strings

Conversation

@thewilkybarkid

Copy link
Copy Markdown
Contributor

Type

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

Description

Schema.NonEmptyArrayEnsure doesn't work with strings. The compiler doesn't recognise that the value being passed to Array.isNonEmptyReadonlyArray might not be an array, and the function only checks the length property which also exists on strings.

Related

  • Related Issue #
  • Closes #

@thewilkybarkid
thewilkybarkid requested a review from gcanti as a code owner August 10, 2026 15:11
@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 37f89d6

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

@effect-slopcop effect-slopcop Bot added 3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3. bug Something isn't working labels Aug 10, 2026
thewilkybarkid added a commit to PREreview/matchmaking-survey that referenced this pull request Aug 10, 2026
`Schema.NonEmptyArrayEnsure` exists, but doesn't work with strings (Effect-TS/effect#7170)
@pullfrog

pullfrog Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Rerun failed job ➔View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@gcanti gcanti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.ensure changes the existing behavior when the value schema itself accepts arrays. For example, an empty array is a valid single value here:

const schema = S.NonEmptyArrayEnsure(S.Array(S.String))

On v3, decoding [] produces [[]]. With Array.ensure, it remains [] and is then rejected by the target NonEmptyArray schema.

Could we preserve that behavior while also checking that non-empty values are actual arrays?

decode: (i) =>
  (Array.isArray(i) && array_.isNonEmptyReadonlyArray(i) ? i : array_.of(i)),

I would also add this regression test:

it("decode array value", async () => {
  const schema = S.NonEmptyArrayEnsure(S.Array(S.String))
  await Util.assertions.decoding.succeed(schema, [], [[]])
})

This should cover both the string fix and the previous empty-array behavior.

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. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants