TypeScript Lesson

March 12th, 2020
typescript

Learned Something Today

It was an interesting day, for sure. I got to work this morning with one task in mind: to see if my changes to the project I had worked on would actually work if I launched it on a local server. Yesterday, I had taken a project one of the other developers had written and refactored it extensively. Initially, when I laid hands on this project, it was one file, over 1600 lines long. I talked to the developer who had written it and asked him about this. He said he had written it under a deadline and just gotten it to work, without worrying too much about the formatting of it. I asked if it would be ok if I split it into a series of files and organized it a bit, and he said he would be happy if I did that. It wasn't his intention to leave it like this; it was just a matter of convenience to write in such a way. Also, up until I joined the team, he was the only one working on it, since he's the only one that knows React on the team. So, I spent the last 2 hours or so of the day yesterday splitting it into different files, and making sure everything was appropriately imported and exported. When I went to start it up this morning, I crossed my fingers, and of course, I got the white screen of death. There were no warnings, just nothingness. After messing around and trying to figure it out, I just asked him what he thought might be the issue. He pointed out I needed to change the state of "isLoading" to false and change the context to reflect the correct step I needed to be on, and when I did so, everything seemed to work fine.

refactor

After this, I knew I needed to get to work on my part in the project, but I didn't know exactly what I was supposed to be doing. The app accepts payment for a quote and I knew I needed to add some sort of companion to this. So, I asked my supervisor on this project about my role, and she called an impromptu meeting with me, my neighbor, her and one of the backend developers. They outlined exactly what they wanted me to do, which was to create a way for their salespeople to directly input a quote amount and accept payment from there without having to actually go through the entire quote process. They wanted a step where the sales agent's ID was checked, and then it would take them to a screen where the quote was calculated. From there, the code wouldn't be much different than how it was; I would just need to manipulate the steps to reflect the data created. It's a difficult task, making my little jQuery project seem like child's play, and I spent the better half of the rest of the day trying to figure out exactly how I would tackle it. I misunderstood initially what they wanted, and ended up building out a different form than they would have wanted. This was after I tried to deconstruct the project and create a new minified version of it, with only the information and components I needed. I failed at this, and decided to go back to the drawing board.

typescript

I went over to my neighbor to try and get some clarification on what he thought I should be doing on the project. He laid it out in a much clearer way that I was able to understand. My communication with him is much better than with the other developers, and I'm able to get the information I need without feeling like I'm exposing my weaknesses. He suggested this would be a good time to transition this project into TypeScript. I told him that sounded awesome, and it would be a great learning experience for me with TypeScript. So, we spent the last 2 hours of the day, moving one file at a time over from JavaScript into TypeScript. I learned so much about TypeScript in the matter of those 2 hours, so much more than I could learn in 2 hours of an online course. There's no better substitute than the experience I'm gaining on the job. Now, I only have a few more files to transition over to TypeScript, and I learned more about the codebase of this project by pouring over it line by line with him than I would have on my own. I know I'm disrupting him from the tasks he needs to complete, but if I'm ever going to be an effective member of the team, I feel it's worth the company's time and his time to mentor me in this way. If they can allow him to take a couple hours out of each day to show me the ropes, I will be way more productive than if they leave me to my own devices. With a codebase this big, even a seasoned developer would have a hard time jumping right in without any guidance in the first week. Regardless, this has been a hell of a week for learning, and I feel like it's only going to go parabolic from here.

Until tomorrow!

Created by Sam Thoyre, © 2019