3 ms·
Yes that's valid TypeScript, but is it good TypeScript? One should take a ternary nested that deep as a sign that refactoring is needed. You can write terrible
by digging 3y ago
Yes that's valid TypeScript, but is it good TypeScript? One should take a ternary nested that deep as a sign that refactoring is needed. You can write terrible code in any language, that doesn't make the language problematic.
- gardenhedge 3y agoAgreed that terrible code can show up in any language. For some reason, I notice it more with TS. Here's a random example too (not saying this is terrible, just confusing to me): https://github.com/prisma/prisma/blob/main/helpers/blaze/utils/types/Strict.ts https://github.com/prisma/prisma/blob/main/helpers/blaze/uti...
- whoknowsidont 3y ago>Yes that's valid TypeScript, but is it good TypeScript? If the implication is that this code should be refactored, then how would you refactor it and why does this class of code show up across many different teams?
- wk_end 3y agoSome combination of: * Javascript devs tend not to be good Typescript devs, and don't always know how to build tasteful or easy-to-type interfaces. * ...or maybe they're perfectly fine Typescript devs, and they've made the deliberate choice to have a nasty type in order to have a particular interface. For better or for worse Typescript offers that flexibility. * Types were added after the fact and it was deemed better to have some kind of gross type for the existing difficult-to-type interface than rebuild the interface and/or implementation.
- digging 3y agoI don't actually know off the top of my head how to refactor it - I've never had to write or deal with a type that complicated. It might actually be the best way of writing that specific type, in which case yes that kind of sucks, but I feel like it's probably not based on how hard it is to parse.