DEV Community

Discussion on: React + TypeScript ❤️: The good parts ⚡

Collapse
 
justinmckenzie profile image
Justin McKenzie • Edited

Great article! I was especially interested since I tried out TypeScript without much background on it in a brand new project at work a few months ago. I ~70% loved it, there were just some really annoying parts I came across that I don't know were other from my naivety or just trade-offs with TypeScript:

  1. Quickly prototyping a component or a helper function is very annoying having to be very explicit with everything, since I'm just trying to get an idea or concept down.

  2. I don't know if I ever fully grasped Generics. My understanding of it is that if you pass a type to an instance of the component/function that uses the generic, that should be the type of passed. In numerous components and functions, I tried to do something like this (ex: a Carousel component that can take both an array of strings or numbers as an "items" prop, or a reduce function that takes an object with a nested array, and it should flatten that array). I just felt like I was constantly having to import/export interfaces and declare them as types on component props or function arguments, and no pun intended, prevented me from keeping them "generic".

  3. Mapping data received from server into the shape that was desired for my pages/components. I found myself having to first declare an interface with the shape of the data received from the server, and then would have to declare yet another interface with the returned value(s) from my mapping. This would turn into an even bigger mess if there were nested objects that had to be transformed. It just seemed so unnecessary to do since I was using this data once after receiving it from fetch, but simply setting any to it is just cheating TypeScript.

Like I said, some of this could just be me not being a full pro in TS, so I appreciate the Resources here to see maybe if I can further my understand. Was interested if you came across any similar issues to me! Thanks