News for hackers. Stuff that matters.
Re:TypeScript: Branded Types by techn00 on Wednesday April 24, 2024 @02:24PM (#40147868)
Very useful for DDD, like having an Email type, or String100 (string of 100 characters)
Re:TypeScript: Branded Types by mason55 on Wednesday April 24, 2024 @03:02PM (#40148200)
Works very well too for any kind of validation or encoding. Anything that accepts input from the outside world can accept a string. And then everything else in the app can work with a "SafeString" and the only way to create a safe string is to send a string through a string escape function (or whatever makes sense for your app).

Works especially well if you're using any kind of hexagonal architecture, make your functional core only accept validated/escaped/parsed/whatever types, and then the imperative shell must send any incoming data through whatever transformation/validation/etc before it can interact with the core.