4 ms·
That’s just plain encapsulation, if I understand you correctly. Branding, on the other hand, prevents complex types from being confused.
by LadyCailin 3y ago
That’s just plain encapsulation, if I understand you correctly. Branding, on the other hand, prevents complex types from being confused.
- mason55 3y agoNot really, not for TS at least. If you just want to take a string and call it an email address and have your function only accept email addresses (the simplest use case) then you need to use branding. That's not encapsulation.
- antifa 2y agoOr double your GC burden by using a wrapper class.
- ebolyen 3y agoBranding works on primitive types as well, which is I think the most interesting use case. I would also agree that it's harder to confuse complex types as any single instance of a type is unlikely to overlap once you have a few fields.