Branded / opaque types, ou un string qui a fait ses preuvesBranded / opaque types, or a string that earned its name
Le structurel rend un Email validé et un string brut interchangeables : sendTo(string) accepte tout. Le brand encode l'invariant validé dans le type — un champ fantôme qui rend Email distinct de string, qu'on n'obtient qu'en passant par un smart constructor. Coût nul à l'exécution (le brand s'efface), à la seule condition de confiner le as. À ne pas brander partout.Structural typing makes a validated Email and a raw string interchangeable: sendTo(string) accepts anything. The brand encodes the validated invariant into the type — a phantom field making Email distinct from string, obtained only through a smart constructor. Zero runtime cost (the brand erases), on the sole condition you confine the as. Don't brand everything.
AudienceAudience
Dev qui modélise en unions discriminées et veut pousser un invariant validé dans une valeur primitiveDev modeling with discriminated unions who wants to push a validated invariant into a primitive value
Format
Self-paced
ChapitresChapters
5
Date
Juin 2026Jun 2026
≈ 18 min●●●○Branded typeNominalTradeoff
🔒
La suite est réservéeThe rest is members-only
Le premier numéro est libre. Débloque tout The TypeScript Loop —
tous les volumes, à vie — pour 5 €, paiement unique.
The first issue is free. Unlock all of The TypeScript Loop —
every volume, forever — for €5, one-time.