4 ms·
The problem with helper functions is that they're often very easy to write, but very hard to figure out the types for. Take a generic function that recursively
by miki123211 1y ago
The problem with helper functions is that they're often very easy to write, but very hard to figure out the types for.
Take a generic function that recursively converts snake_case object keys to pascalCase. That's about 10 lines of Javascript, you can write that in 2 mins if you're a competent dev. Figuring out the types for it can be done, but you really need a lot of ts expertise to pull it off.
- shakow 1y agoNot really familiar with TS, but what would be so weird with the typing? Wouldn't it be generic over `T -> U`, with T the type with snake_case fields and U the type with pascalCase fields?
- cyborgsquirrel 1y agoTurns out in TypeScript you can model the conversion of the keys themselves from snake_case to pascalCase within the type system[0]. I assume they meant that this was the difficult part. [0]: https://stackoverflow.com/questions/60269936/typescript-convert-generic-object-from-snake-to-camel-case#65642944 https://stackoverflow.com/questions/60269936/typescript-conv...