Type migration is the process of adding types to untyped code to gain assurance at compile time. TypeScript and other gradual type systems facilitate type migration by allowing programmers to start with imprecise types and gradually strengthen them. However, adding types is a manual effort and several migrations on large, industry codebases have been reported to have taken several years. In the research community, there has been significant interest in using machine learning to automate TypeScript type migration. Existing machine learning models report a high degree of accuracy in predicting individual TypeScript type annotations. However, in this paper we argue that accuracy can be misleading, and we should address a different question: can an automatic type migration tool produce code that passes the TypeScript type checker? We present TypeWeaver, a TypeScript type migration tool that can be used with an arbitrary type prediction model. We evaluate TypeWeaver with three models from the literature: DeepTyper, a recurrent neural network; LambdaNet, a graph neural network; and InCoder, a general-purpose, multi-language transformer that supports fill-in-the-middle tasks. Our tool automates several steps that are necessary for using a type prediction model, (1) importing types for a project's dependencies; (2) migrating JavaScript modules to TypeScript notation; (3) inserting predicted type annotations into the program to produce TypeScript when needed; and (4) rejecting non-type predictions when needed. We evaluate TypeWeaver on a dataset of 513 JavaScript packages, including packages that have never been typed before. With the best type prediction model, we find that only 21% of packages type check, but more encouragingly, 69% of files type check successfully.
翻译:类型迁移是将类型添加到非类型代码中以在编译时间获得保证的过程。 TypeScript 和其他渐进类型系统通过允许程序员以不精确的类型启动并逐步加强它们来便利类型迁移。 但是, 添加类型是一种手工努力, 大型行业代码库上的一些迁移已经花费了几年时间。 在研究界, 使用机器学习将 TypeScript 类型迁移自动化非常感兴趣 。 现有的机器学习模型在预测个人 TypeScript 类型说明时报告高度准确性 。 然而, 在本文中, 准确性系统可以误导, 我们应该解决一个不同的问题: 自动类型迁移工具能够生成通过 TypeScript 类型检查器的代码? 我们介绍TyWepeWecript 类型迁移工具工具, 可以使用任意类型预测模型进行自动类型迁移。 我们用三个模型来评价Typeweaver, 一个经常性网络; 蓝巴Net, 一个图表型的神经网络, 一个普通、 多语言的模型变换器, 用来支持在输入Syperiple StypealterS 类型Stypeal 类型 Stypeal 类型中, tystelick 这样的程序类型中, 在输入类型中, 类型中, 类型中, 类型中, 需要一个自动输入类型中, 需要一种输入的输入类型Stypealtypealtypealxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,, 需要输入, 。