DEV Community

Discussion on: Key Headaches in TypeScript

Collapse
 
sirseanofloxley profile image
Sean Allin Newell

I feel this pain. I've been doing TS for a few years now, and the best strategy I've come up to tackle things like this is to write my function, write out a hindley minler type annotation, write a return TS type, and then see how the inputs and outputs relate.

Sometimes the TS Handbook's advanced types help, sometimes libraries like fp-ts help, and sometimes i just sprinkle some any until I come back tmrw or next week with more experience and find a better+simpler expression.

I think there's value in this struggle, keep on it! TS is very keen on helping us write higher quality code (ie type correctness) with confidence.

I don't know who told you you'd pick it up right away; but I helped lead a hardcore C# team to a new TS project recently and it was definitely not easy.

<3

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Excellent feedback! And FWIW, this "headache" doesn't inspire me to drop TS. But sometimes it just feels to me like I'm "defining" things that really shouldn't need to be defined (e.g., generic object keys).

I know there's value in the "come back tmrw or next week with more experience and find a better+simpler expression" advice. If I were on a project with a critical deadline, I'd probably follow it. The blessing right now (or maybe it's a curse) is that we have some "down time" while they're assembling the team. And since we don't have to deliver anything right now, it definitely stokes my "developer sense" whenever I'm tempted to slap an any on something and just move on. In the long run, that will be valuable. In the short term, it's... frustrating.

As for the C# experience, I certainly understand that as well. I wrote a lot of C# - but it's been several years. And, as you've alluded to, even if I were coming straight from C#, I'm not sure that all of the translations would be second-nature, even if the syntax of TS looks much more familiar to a C# dev.

Cheers!