0

I have some equivalent types that represent unique Ids:

type FlanId = string;
type BranId = string;

While these are actually the same type under the hood. I would like for them to be incompatible with each other.

So this should be ok:

f: FlanId = "43492393"
b: BranId = "05903242"

but then

f = b

should throw a typescript error.

Is this possible?

kaan_a
  • 3,503
  • 1
  • 28
  • 52
  • 2
    See https://github.com/microsoft/TypeScript/wiki/FAQ#can-i-make-a-type-alias-nominal – jcalz Feb 16 '22 at 21:33
  • This is almost certainly a duplicate question but I’m on mobile now so I can’t search effectively. – jcalz Feb 16 '22 at 21:34
  • I tried searching for "typescript and nominal" and came up with a few results. Thanks @jcalz – kaan_a Feb 16 '22 at 21:47

0 Answers0