3 ms·
>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
by 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.