将370万行Flow代码迁移到TypeScript

Authors: Jack Hsu | Staff Software Engineer, Core Web Platform; Mark Molinaro | Staff Software Engineer, Code and Language Runtime

作者: Jack Hsu | 员工软件工程师,核心网络平台; Mark Molinaro | 员工软件工程师,代码和语言运行时

Pinterest migrated 3.7 million lines of code from Flow to TypeScript in eight months, leading to better type safety, developer experience, and improved hiring. Along the way, we learned a lot and greatly benefited from the open source community, and it’s our turn to give back. Today, we’re excited to share our learnings and contributions to Stripe’s flow-to-typescript codemod!

Pinterest 在八个月内将 370 万行代码从 Flow 迁移到 TypeScript,带来了更好的类型安全性、开发者体验和改善的招聘。在这个过程中,我们学到了很多,并从开源社区中受益匪浅,现在轮到我们回馈了。今天,我们很高兴分享我们的经验和 贡献Stripe 的 flow-to-typescript codemod

Why?

为什么?

In 2016, Pinterest began adding types to our JavaScript codebase. At that time, we chose Flow over TypeScript for several reasons:

在 2016 年,Pinterest 开始为我们的 JavaScript 代码库添加类型。那时,我们选择了 Flow 而不是 TypeScript,原因有几个:

  1. Gradual Adoption: Flow allowed for easier incremental adoption, which was crucial since we had no static type checking and needed to add types file-by-file.
  2. 渐进式采用: Flow 允许更容易的增量采用,这一点至关重要,因为我们没有静态类型检查,需要逐个文件添加类型。
  3. Working with React: Flow, which was open sourced by Meta, appeared more future-proof — particularly with React, which was also open sourced by Meta — promising seamless integration.
  4. 与 React 一起工作: Flow 是由 Meta 开源的,显得更具未来保障——特别是与同样由 Meta 开源的 React,承诺无缝集成。

However, over the years, the industry settled on TypeScript as the standard for JavaScript type checking. This is reflected in npm download trends:

然而,多年来,行业已将 TypeScript 确定为 JavaScript 类型检查的标准。这在 npm 下载趋势 中得到了体现:

In late 2023, we decided to adopt TypeScript for the following reasons:

在2023年底,我们决定采用 TypeScript,原因如下:

  • Feasibility: We achieved 100% Flow coverage and a variety of OSS Flow-to-TS migration tools were released, meaning we could migrate in a single (massive) commit!
  • 可行性: 我们实现了 100% 的 Flow 覆盖,并发布了多种 OSS Flow 到 TS 的迁移工具,这意味着我们可以在一次(巨大的)提交中完成迁移!
  • Better Community Support: In terms of both community a...
开通本站会员,查看完整译文。

inicio - Wiki
Copyright © 2011-2025 iteam. Current version is 2.143.0. UTC+08:00, 2025-05-03 15:14
浙ICP备14020137号-1 $mapa de visitantes$