From 37f89d67151a1a74653cf75900118b0a514fb50f Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Mon, 10 Aug 2026 16:06:06 +0100 Subject: [PATCH] Fix use of Schema.NonEmptyArrayEnsure with strings --- .changeset/slimy-swans-repeat.md | 5 +++++ packages/effect/src/Schema.ts | 2 +- .../effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/slimy-swans-repeat.md diff --git a/.changeset/slimy-swans-repeat.md b/.changeset/slimy-swans-repeat.md new file mode 100644 index 00000000000..ca5c5ec3fd1 --- /dev/null +++ b/.changeset/slimy-swans-repeat.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Fix use of Schema.NonEmptyArrayEnsure with strings diff --git a/packages/effect/src/Schema.ts b/packages/effect/src/Schema.ts index 08719a018d5..e4f7319d752 100644 --- a/packages/effect/src/Schema.ts +++ b/packages/effect/src/Schema.ts @@ -1664,7 +1664,7 @@ export interface NonEmptyArrayEnsure export function NonEmptyArrayEnsure(value: Value): NonEmptyArrayEnsure { return transform(Union(value, NonEmptyArray(value)), NonEmptyArray(typeSchema(asSchema(value))), { strict: true, - decode: (i) => array_.isNonEmptyReadonlyArray(i) ? i : array_.of(i), + decode: (i) => array_.ensure(i) as never, encode: (a) => a.length === 1 ? a[0] : a }) } diff --git a/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts b/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts index ec26ef4e68c..c265d9941d7 100644 --- a/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts +++ b/packages/effect/test/Schema/Schema/NonEmptyArrayEnsure.test.ts @@ -5,7 +5,9 @@ import * as Util from "../TestUtils.js" describe("NonEmptyArrayEnsure", () => { it("decode non-array", async () => { const schema = S.NonEmptyArrayEnsure(S.NumberFromString) + const schema2 = S.NonEmptyArrayEnsure(S.String) await Util.assertions.decoding.succeed(schema, "123", [123]) + await Util.assertions.decoding.succeed(schema2, "foo", ["foo"]) await Util.assertions.decoding.fail( schema, null,