Effect CommunityEC
Effect Communityβ€’16mo agoβ€’
42 replies
danielo515

Advantages of Using Type-Fest's Opaque Type vs. Branded Interface in TypeScript

Hello. This is kind of a niche question, so it is very hard to google it, hope you don't mind me asking it here.
What is the advantage of using the helper Opaque type from type-fest with a branded interface vs an intersection with the same branded interface directly?
I mean, instead of this:
type X = Opaque<string,Xbrand>

Do just this:
type X = string & Xbrand

Where x brand looks like this:
interface XBrand {
  readonly X: unique symbol;
}

I assume there is some benefit, but I couldn't see it
Was this page helpful?