4 ms·
In our codebase this will never be allowed: type ColorHexValue = `#${string}` type ColorRGBValue = `rgb(${number},${number},${number})` At least one developer
by rwalle 4y ago
In our codebase this will never be allowed:
type ColorHexValue = `#${string}`
type ColorRGBValue = `rgb(${number},${number},${number})`
At least one developer will ask to find an alternative -- use actual CSS names or use a function to create these strings, treat them as strings and forget all those funky typing, becausenobody knows what color a combination of HSV values looks like and nobody would be able to maintain that code. Just because it is possible doesn't mean people should use it.
- saiojd 4y agoI don't understand what you meant by "nobody knows what color a combination of HSV values" (but you quote HEX strings)? What makes the quoted code hard to maintain?
- mablopoule 4y agoAgreed. I like CSS, but the article (while interesting and informative) give me PTSD thinking about a previous project with "typed" CSS. Maybe I'm an old fart, but I never saw the appeal in having such a thorough level of typing. The downside is longer time to analyse your Typescript code, having to reference some ungodly type if you need to pull your value from a config file, while the upside is just... something that most IDE already did anyway? In most case, I'm pretty sure it's less of an hassle to say it's a damn string and check that your code give some correct value there, instead of trying to rube-goldberg Typscript into auto-generating the correct code. Typescript is powerful, but KISS is good too.