Developers are starting to write large and complex applications in TypeScript, a typed dialect of JavaScript. TypeScript applications integrate JavaScript libraries via typed descriptions of their APIs called declaration files. DefinitelyTyped is the standard public repository for these files. The repository is populated and maintained manually by volunteers, which is error-prone and time consuming. Discrepancies between a declaration file and the JavaScript implementation lead to incorrect feedback from the TypeScript IDE and, thus, to incorrect uses of the underlying JavaScript library. This work presents dts-generate, a tool that generates TypeScript declaration files for JavaScript libraries uploaded to the NPM registry. It extracts code examples from the documentation written by the developer, executes the library driven by the examples, gathers run-time information, and generates a declaration file based on this information. To evaluate the tool, 249 declaration files were generated directly from an NPM module and 111 of these were compared with the corresponding declaration file provided on DefinitelyTyped. All these files either exhibited no differences at all or differences that can be resolved by extending the developer-provided examples.
翻译:开发者开始在 TypeScript 中写入大型复杂的应用程序。 TypeScript 将 JavaScript 应用程序通过输入描述其 API 被称为 声明文件, 将 JavaScript 库整合为 dts-generate 。 TempleTTempleTyScript 是这些文件的标准公共储存库。 该存储器由自愿者手动配置和维护, 容易出错且耗时。 声明文件和 JavaScript 执行过程之间的差异导致来自 TypeScript IDE 的错误反馈, 从而导致对 JavaScript 库的错误使用。 这项工作展示了 dts- generate, 这是为 JavaScript 图书馆生成 Typeript 声明文件的工具, 这个工具被上传到国家防范机制登记处。 它从开发者所编写的文件中提取了代码示例, 执行由示例驱动的图书馆, 收集运行时间信息, 并根据此信息生成声明文件, 直接生成了 249 声明文件, 其中111 与相应的声明文件进行了比较。