News for hackers. Stuff that matters.
Re:TypeScript: Branded Types by dvt on Thursday April 25, 2024 @02:49PM (#40161497)
Function signatures already solve that problem. We have all kinds of functions that take two numbers that mean different things (width/height, x/y, etc.). Branding seems like a solution looking for a problem. I just think it's too much overhead and confusion for too little gain.

In fact, a common pattern is to pass fully-qualified objects, e.g. `dimensions = {width: number, height: number}`, which makes mixing up variables even less likely since you have to explicitly specify them.

Re:TypeScript: Branded Types by kristiandupont on Friday April 26, 2024 @02:47AM (#40166560)
>Function signatures already solve that problem.

I literally just showed you how they don't. And you even go on to describe a pattern that makes the problem "even less likely" in the next sentence..

>Branding seems like a solution looking for a problem.

You do you.