Checking correctness of TypeScript interfaces for JavaScript libraries

Checking correctness of TypeScript interfaces for JavaScript libraries
复制标题

检查 JavaScript 库的 TypeScript 接口的正确性

DOI:
--
复制
发表时间:
2014
期刊:
Conference on Object-Oriented Programming Systems, Languages, and Applications
影响因子:
--
通讯作者:
Anders Møller
Anders Møller
中科院分区:
--
文献类型:
--
作者:
Asger Feldthaus;Anders Møller

文献摘要

被引文献

相似文献

Typescript编程语言将可选类型添加到JavaScript,并支持通过接口声明与现有JavaScript库进行交互。此类声明已为数百个库编写,但是它们可能很难编写并且通常包含错误,这可能会影响IDE中应用程序代码的类型检查和误导代码完成。我们提出了一种务实的方法,以检查有关JavaScript库实现的打字稿声明文件的正确性。我们算法中的关键思想是,可以通过对库初始化状态以及对库功能代码的轻量静态分析进行分析来检测许多声明错误。我们的实验结果证明了该方法的有效性:它在10个库的声明文件中发现了142个错误,每个库的分析时间为几分钟,误报数量较低。我们对程序员使用库接口声明的分析还揭示了打字稿类型系统的一些实际局限性。
The TypeScript programming language adds optional types to JavaScript, with support for interaction with existing JavaScript libraries via interface declarations. Such declarations have been written for hundreds of libraries, but they can be difficult to write and often contain errors, which may affect the type checking and misguide code completion for the application code in IDEs. We present a pragmatic approach to check correctness of TypeScript declaration files with respect to JavaScript library implementations. The key idea in our algorithm is that many declaration errors can be detected by an analysis of the library initialization state combined with a light-weight static analysis of the library function code. Our experimental results demonstrate the effectiveness of the approach: it has found 142 errors in the declaration files of 10 libraries, with an analysis time of a few minutes per library and with a low number of false positives. Our analysis of how programmers use library interface declarations furthermore reveals some practical limitations of the TypeScript type system.