Effect CommunityEC
Effect Community3y ago
4 replies
Deleted User

Difficulty creating a union of branded types using `@effect/schema`

I think this is going to be an easy one, but I haven't figured it out in ~45 minutes. I did search "union" and "branded" but didn't find an existing Q on this.

Using
@effect/schema
and trying to make a union of branded types. I tried this creating the branded types with Schema directly, but I get several hundred lines of type errors just from the below. I'm pretty sure I'm creating the union incorrectly but am not sure what the right mechanism for including branded types is.

type GenPassword = string & Brand.Brand<"GenPassword">
const GenPassword = Brand.nominal<GenPassword>()

type UserSecret = string & Brand.Brand<"UserSecret">
const UserSecret = Brand.nominal<UserSecret>()

const Secret = S.union(
  S.string.pipe(S.fromBrand(GenPassword)), 
  S.string.pipe(S.fromBrand(UserSecret))
)
Was this page helpful?