Effect CommunityEC
Effect Community3y ago
5 replies
Stephen Bluck

Nice type output for brands

Is there a way to get a nice type output from schema brands?

We can get a nice type by using nominal:
type UserId = string & B.Brand<"UserId">;
const UserId = B.nominal<UserId>();

// UserId (yey!)
const userId = UserId("asd")

But deriving from schema it gets "uglied" (I made this word up):
const UserId = pipe(S.string, S.brand("UserId"));
type UserId = S.To<typeof UserId>;

// string & B.Brand<typeof UserId> (ewww)
const myUserId = UserId("asd")

I have also tried deriving from an exisiting brand:
const UserIdSchema = pipe(S.string, S.fromBrand(UserId));
// string & B.Brand<typeof UserId> (ewww)
const userId = S.parse(UserIdSchema)("asdasd")
Was this page helpful?