Is TypeScript in ReactJS a good idea for a small team?
"I'd finish this component days ago coding Vanilla JavaScript!" - Anonymous Crew2Captain developer.
Background
Let me start with some background of the project and the team. Crew2Captain is a community-oriented platform with the main goal to connect people who own boats with people who enjoy water activities so that they can share the trips. We have a small team of 4 developers and 3 analysts. All of us are fulltime employed, and each can spare no more than 10 hours weekly. Hence, one of our priorities is to make these hours as productive as possible. The level of developers in the team various from Grad to Senior and only 1 developer has had experience with strictly typed languages.
We started the project with vanilla js. That worked beautifully, the flexibility and the coding pace was at the pick. Then we realised our initially tiny project might grow to something enormous. Hence, we had to frame it into the best practices from the very beginning and as much as possible.
Reasons
The reasons switching to TypeScript were very pragmatic as well as romantic ?? (1) we started encountering errors with passed properties in the common and shared components. (2) we read more about the best practices, and they often mentioned switching to TypeScript, especially if you expect medium to large codebase, and we hope our project will be somewhat in between ??. Finally, (3) we decided that TypeScript would benefit our careers because there are more and more positions with this skill as a mandatory requirement.
Crysis
TypeScript introduction wasn't something unexpected; we had long sessions and much individual reading prior. However, that was still a shock for our developers. We were paralysed first weeks: fighting bugs and unfamiliar exceptions. We had to change the way we were coding, introduce new entities and standards. We stopped progressing and even buried a couple of sprints (Rest in Peace Sprint 6 and Sprint 7 ??). And honestly, that looked like a disaster at that time. I stopped counting how many times the question "can we rollback to Vanilla?" raised on our standups and daily updates. Still, we kept pushing it forward like those ultra-marathon runners, who're questioning themselves "What am I doing? Why am I here? Why am I making myself struggle?" I've never run a marathon but assume these champions must have such thoughts, or they're aliens ??
Rainbow & Unicorns
But there's always something good at the end, isn't it? One sprint review, we noticed something magical: no complains about TypeScript from the developers (yeah, they are still complaining but about something else these days ??), and more smiles during the video calls... ah, we don't usually have video calls ??, but I'm pretty sure they were smiling ??.
So what changed? I believe we passed the "language" barrier stage and finally built the foundation. We finished all the required interfaces for our components and learned the ways to design them better. We started utilising Enums, Types, Generics and other features heavily preventing possible future errors and reducing the amount of the code required. Hence, we reached the enlightenment stage. ??
Worth it?
Yes, it is. Was there a struggle? - Yes, there was. However, we definitely matured as professionals and improved our performance in the end.
An attentive reader may ask about the time we spent adjusting to TypeScript and those dead sprints. But I believe, that turned to an excellent investment and my only regret is that we didn't do it earlier. Today, we are protected from "wrong value/type" errors, and thanks to Types & Enums we don't have any hardcoded stuff nor string constants, which often results in unpredictable errors. We write less code and program more elegant with generics. Developers spend less time understanding interactions with shared components because all inputs are quite descriptive. And there are not enough words to praise the interfaces! They help us to describe properties; we reuse them to define backend entities and the global state (which is redux and which is another story ??)
I read many articles which recommend to not TypeScript for a smaller team and/or smaller projects. My opinion, if you're coding alone your pet project, go with TypeScript from the beginning! First of all, you never know where the journey takes you, and secondly, in the worst case, you'll add a killer skill to your CV. For a team which starts a "greenfield" project, regardless of the size, TypeScript is a must, the reasons above.
A lame tip
Avoid using `any` type as much as possible. It may seem harmless, but I learned it the hard way. TypeScript compiles to vanilla js at the end, and you may be stuck in the long debugging session trying to understand why `(10 < 3) === true` when in fact you're comparing two strings.
Final words
I'm a fortunate person who has worked with such legends as @Vladimir Abramov, @Klemen Abrams, @Irina Dmitrenko, @Kirill Kholine, @Malik Omonov, @Ian Bobek, @Igor Doinikov, @Johnny Samoletov, on Crew2Captain project.
You never afraid of the challenges and always willing to learn new stuff. You always step up and get things done. Thanks for being such fantastic team players, for your motivation and hard work.
And thank you, the reader, for making it to the final line, have a great day! ????