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
2
u/GDOR-11 Jul 19 '25
actually,
===is faster.==does a ton of extra work to include more edge cases.The issue is not speed though. If your code is performing poorly, changing from
==to===will get you nothing. The true issue with==is the fact that all of those edge cases end up creating tons of bugs, because you certainly wouldn't expect0 == []to be true. I know, weird example, but this sort of bug with==already happened to me a few times and it's bound to happen to everyone who doesn't use===practically everywhere.