News for hackers. Stuff that matters.
Re:TypeScript: Branded Types by LadyCailin on Wednesday April 24, 2024 @02:23PM (#40147859)
That’s just plain encapsulation, if I understand you correctly. Branding, on the other hand, prevents complex types from being confused.
Re:TypeScript: Branded Types by ebolyen on Wednesday April 24, 2024 @03:18PM (#40148399)
Branding 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.

Re:TypeScript: Branded Types by mason55 on Wednesday April 24, 2024 @03:04PM (#40148219)
Not 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.
Re:TypeScript: Branded Types by antifa on Thursday April 25, 2024 @10:52AM (#40158296)
Or double your GC burden by using a wrapper class.