Migrating 3.7 Million Lines of... Note

Migrating 3.7 Million Lines of Flow Code to TypeScript

Pinterest migrated 3.7 million lines of code from Flow to TypeScript in eight months, resulting in better type safety, developer experience, and improved hiring. The company initially chose Flow over TypeScript in 2016 due to its gradual adoption and seamless integration with React. However, as the industry settled on TypeScript as the standard for JavaScript type checking, Pinterest decided to adopt it for its better community support, language features, and talent availability. The migration was done using a "big bang" approach, dividing the process into three phases: setup, conversion, and integration. The setup phase involved configuring TypeScript and @typescript-eslint, while the conversion phase involved migrating dependencies, running codemods, and suppressing ESLint errors. The integration phase focused on adapting existing systems to function within the new TypeScript environment. The company wrote a script to automate the entire process, minimizing merge conflicts and manual intervention. After validating the migration through daily automated testing, multiple rounds of manual testing, and byte-for-byte static analysis, Pinterest successfully rolled out the TypeScript branch. The company learned a lot from the open-source community and contributed to Stripe's flow-to-typescript codemod. Pinterest's experience serves as a valuable lesson for other companies considering a similar migration.
CdXz5zHNQW_u2LVnNpu5X.png