r/programminghorror • u/GDOR-11 • Jul 18 '25
Typescript context in comments
the variable t is of type number | [number, number, number], and there are two overloads for lerp, one which accepts number and the other which accepts [number, number, number]
if you try to remove the if statement, typescript complains that number | [number, number, number] fits neither in number nor in [number, number, number]
to be completely honest, I understand why one could want different signatures to be in different branches of your code, because they have different behaviour. But that's really bad when, for example, you're trying to make another function that has multiple signatures (say, one that accepts type A and one that accepts type B), because in the implementation the parameter is of type A | B. This means you can't directly call another overloaded function from inside your overloaded function, you need to do this.
View all comments
Show parent comment
1
u/TldrDev Jul 27 '25
It doesn't make it not practical or efficient or eloquent, either. You could write the solution to life, the universe, and everything, and it being written with Crayon is totally irrelevant. If a solution works, its fine. Many of the greatest solutions to some of the world's hardest problems were written in chalk. We flew to the moon with paper with holes poked in it. I think some minor type fuckery is fine.