Strongly Typed

May 28th, 2020
typescript

Getting Serious with TypeScript

I'll start out the entry today talking about my coursework I've been taking at night. I haven't hit the books yet today, but I did get quite a bit of studying in this week. I've been working on a 54 hour microservices course that is really extensive. Of course, in 54 hours, a lot of material is typically covered, and this is no exception. I've been getting through it alright, but a lot of this work is falling on the backend. We are currently creating a massive project that is basically a clone of StubHub, and it's getting a little crazy. I'm getting a ton of practice in with TypeScript, which is great, but it's mostly focused on usage within Express and Node. There is a lot that transfers over, but there's also a lot of class based work that I just don't ever come across on the frontend in the React world. There is rarely a case where I would use a class for anything. Even in most of the third party packages, classes are only used under the hood. I would like to get more comfortable in the Object Oriented side of programming, but it's not completely necessary in my realm of work. I know if I get into the backend at my current job, we use ASP.net, and C# is based on classes. So, it would definitely be beneficial to get better in this area.

typescript

So far, we have created several microservices. We've only spent a little time so far on the frontend, building a NextJS application. We've really only set up the authentication for the frontend, but that was pretty extensive in and of itself. We have a really in-depth authentication microservice, which took a ton of time. That was ridiculous and I'm glad it's mostly in the past. Then, we created a tickets microservice, and started using NATS streaming service for publishing and listening to events. With this pattern in place, we started creating the orders microservice, as well. A lot of the logic is being shared across multiple services, so we created a common module and published this to NPM so we could import it into each service. This was the first time I had published a package on NPM, and I'm really glad I got that experience. This isn't something that is often talked about in job summaries, but I think it's a really valuable skill, on par with being able to use Git and Github. We still have a long way to go in the orders service, but after that, we're going to bring it back to the frontend and hook some of this backend logic up. We still have to create a payments system with Stripe, so I still have a ways to go. Out of the 54 hours, I have about 20% left, so I'm getting there.

typescript

At work, I spent the entire day going deep into TypeScript land. Throughout the creation of the 2 screens in the past month, I've left several things a little untidy. There were more "any" descriptions of variables or elements than I cared for, so I started combing through it. Yesterday, I got rid of a ton of strings in the application and replaced them with enums to reduce human error. From there, I was able to use these enums to describe certain variables and elements a little more clearly. So, instead of saying something is a string, I can say it's of a specific enum. I also went through the forms with React Hook Form and figured out the best way to handle these types. It is pretty well documented, and I was able to get what I needed from the types files associated with this project. Now, if I have an input that has a name, that name is tied to an enum, and the enum is tied to the form hook, so you couldn't possibly add something that's not supposed to be there. The best thing I did all day, though, was make the types on my reducer on one of my screens flawless. I found a blog entry that was a great guide to how to type this out a little better. I typed each different action, then created a type that managed all of the action types. With the state, I created an interface to define this more succinctly. Overall, this is another place where you couldn't possibly enter something that wasn't supposed to be there, plus I now have the added benefit of intellisense. I have a ways to go in learning TypeScript, but I'm making great strides.

Until tomorrow!

Created by Sam Thoyre, © 2019