-
-
Notifications
You must be signed in to change notification settings - Fork 490
Closed
Description
What version of Effect is running?
3.19.5
What steps can reproduce the bug?
When using Schema.transform with branded types, the brand is lost during the encode operation. The From/To branding is not preserved when encoding back from the transformed type.
import * as Schema from "effect/Schema";
const BrandedBool = Schema.Boolean.pipe(Schema.brand("bool"));
const BrandedString = Schema.String.pipe(Schema.brand("string"));
const BoolFromString = Schema.transform(BrandedString, BrandedBool, {
strict: false,
decode: (i) => i === "on",
encode: (bool) => (bool ? "on" : "off"),
});
const bool = BrandedBool.make(false); // boolean & Brand<"bool">
const stringFromBool = Schema.encodeSync(BoolFromString)(bool); // Expected: string & Brand<"string">, Actual: string
const boolFromString = Schema.decodeSync(BoolFromString)(stringFromBool); // boolean & Brand<"bool">What is the expected behavior?
Schema.encodeSync(BoolFromString)(bool) should return string & Brand<"string"> because BrandedString is used as the From type in the transformation.
What do you see instead?
Schema.encodeSync(BoolFromString)(bool) returns string without the brand. The Brand<"string"> is stripped during encoding.
Additional information
No response
Metadata
Metadata
Assignees
Labels
No labels