Menu

πŸ“°
0

Reddit - Please wait for verification

TypeScriptΒ·/u/Oddball7478Β·3 days ago
#WbAb8ejO
Reading 0:00
15s threshold

We type our API responses, our props, our state. CSS-in-TS libraries like vanilla-extract type the output. But the values going in? Still strings. Still unchecked. Nobody stops you from adding pixels to degrees. Nobody catches a typo in a token name until it breaks in production. The type system is right there, and we're not using it for the part that actually breaks. I built a small library that types CSS measurements at the input: import { m } from "css-calipers"; ​ const base = m(8); // typed as px const pad = base.add(4).css(); // "12px" ​ const rotation = m(45, "deg"); base.add(rotation); // compile error: px + deg Units stay checked through composition. Nothing emits a string until .css() at the boundary. Mismatched units are a compile error, not a production surprise. Best used at build time (I use it with vanilla-extract, but it's framework-agnostic). Runtime works too, but build time is where it shines.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More