Migrating to TypeScript
I spent the previous few years working in Swift, which is strongly typed. This means that Swift code will not compile if you try to pass a
Dog model object into a function expecting a
To identify the input types of a function or class, I added breakpoints and console.log to my code. This is time consuming and repetitive. My productivity slowed. I was frustrated.
- I wrote a few key files in Flow and TypeScript, then documented the process.
- I showed the files to my team members, and gathered feedback.
After the pilot, as a team, we decided to move forward with a 3-month rollout of TypeScript. We chose TypeScript over Flow because TypeScript had strong developer backing. We liked that Flow didn't actually change our code, since types are added with code comments. But, we felt that the strong developer roadmap for TypeScript trumped the pros of Flow.
The 3-month rollout was planned as follows:
- All new code was to be written in TypeScript.
The goal with these rules was to dive head-first into TypeScript as a team, but not get bogged down in a full codebase re-write. Though tempting to convert the entire project to TypeScript, we needed to maintain strong productivity on feature work. Also, I wanted us to be able to move away from TypeScript if the 3-month rollout was a failure.
After the rollout
Over the next three months, we had a few pain points as we rolled out TypeScript to the whole team. First, I struggled to integrate TypeScript into our custom eslint configuration. I accidentally configured our project so that there were collisions between eslint and TypeScript. Unknowingly, this meant that we shipped code for a week or two that didn't conform to eslint. The ultimate fix was easy, requiring a tweak to our tsconfig file. However, that hiccup showed me that it is important to nail down all configuration setup before embarking on a team-wide pilot like this.
- The benefits of TypeScript are strongest when working with multiple engineers.
- With TypeScript, we experience fewer bugs because collaborators know what functions expect.
- With TypeScript, engineers have better productivity because of syntax highlighting and auto-completion inside of VSCode.
- TypeScript can be added incrementally to a code base, slowly improving its type coverage. A full refactor or re-write of a code base isn't needed.