Types


Types. Are. Important.

I'm working with a codebase littered with weights. It's written in TypeScript, but weight unit is stored as a "string". 👎

Result? The code has 120 references to weight, all with varying formats:

lb.
lbs.
pound
kg
Kg
Kilo

😬

Solution: A union type.

Now I'm just wondering: How many bugs are in this code because the conditional is

if (weightUnit === "lb.")

when it should be

if (weightUnit === "lb")

Types make this mistake impossible. 👍

View original on X