:: krowemoh

Friday | 27 DEC 2024
Posts Links Other About Now

previous
next

Thoughts on Typescript

2021-12-28

The reason I wanted to switch to using typescript in my project was to add some typechecking and make my code more robust. I have 0 testing coverage and I already ran into dumb bugs that I think I should really be testing for but instead of adding tests, I figured typescript might be my out. Boy, was I wrong! This just made me dislike typescript more. (I still love typescript as a whole, just for this project it was a pain in the ass, I hope that I can read this post in the future and see all these things disappear.)

I've written a number of products in typescript now and the same problem keeps stopping me from using it as a replacement for javascript. The first thing is the compilation step. The build step is actually a big pain point for me. I like being able to iterate quickly and even a compiled language is fine if I'm using something like nodemon or cargo-watch to automatically build things but typescript compiles so slowly comparatively. It takes me out of the flow of things.

Transforming my web project to use typescript was what actually killed the momemntum for me. I took a month break after wiring it up to work with typescript because I screwed up by not backing up before doing the roll out. The migration to typescript was pretty straightforward but the building and waiting killed my motivation.

The next thing that took me out of using typescript was the finnickiness of the build system. I had to set up my express project under a src directory and then build into dist directory. Which, conceptually makes sense but was pain in the ass to get going. There was also weirdness in how files were watched and how es-lint was running. Lots of little things made the tooling around typescript such a kill joy that I never want to do it again. I think this is very much because I was trying to convert an existing project to typescript and I probably would have a much better time if I wrote typescript from the beginning like I have with other projects.

The last thing that bothered me with typescript was the magical class stuff I had to do do to get sessions and the like to work. I understood none of the changes I was making but got it to work but I didn't like that there was parts of the code that I basically was copy and pasting and modifying into working. Obviously I understood part of it because I had to make changes but it was like I knew the rules of how it worked so I could force my code to fit into it but I didn't understand the rules themselves.

So this is why my leftwrite project went back to using plain javascript. I thought typescript would help make it more professional and it very well might but I'd rather have code that I enjoy working on than it being easier for the future to deal with. I definitely would give up on the project if I actually had to use typescript. Maybe in the future this will change but for now I'm very happy that I made the change to go back to plain old javascript.