一句话:提出 FlexType——一个可插拔的 IDE 扩展,能在 JavaScript 与 TypeScript 中交互或自动推断类型。
TypeScript 中的类型对变量与 API 的正确使用至关重要,显式类型标注可以避免变量或函数误用带来的类型错误。本文提出 FlexType:一个运行于 IDE 中、同时支持 JavaScript 与 TypeScript 的扩展,能够以交互式或全自动的方式推断类型,并作为类型推断模型的即插即用框架使用。作者在 JavaScript 上开展实验,考察若用 FlexType 将主流 JavaScript 项目迁移到 TypeScript,它能解析出多少类型。结果显示,FlexType 能以高精度与高置信度为全部类型中的 56.69% 完成标注,其中既包括原生类型,也包括从模块导入的类型。除自动推断外,作者认为该 Visual Studio Code 交互式扩展在 TypeScript 与 JavaScript 中都具备固有价值,尤其在类型推导对开发者而言负担较重的情况下更为有用。
Types in TypeScript play an important role in the correct usage of variables and APIs. Type errors such as variable or function misuse can be avoided with explicit type annotations. In this work, we introduce FlexType, an IDE extension that can be used on both JavaScript and TypeScript to infer types in an interactive or automatic fashion. We perform experiments with FlexType in JavaScript to determine how many types FlexType could resolve if it were to be used to migrate top JavaScript projects to TypeScript. FlexType is able to annotate 56.69% of all types with high precision and confidence including native and imported types from modules. In addition to the automatic inference, we believe the interactive Visual Studio Code extension is inherently useful in both TypeScript and JavaScript especially when resolving types is taxing for the developer.