Abstract
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.
- R. Chugh, D. Herman, and R. Jhala. Dependent types for JavaScript. In Proc. 27th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, 2012. Google Scholar
Digital Library
- A. Feldthaus and A. Møller. Semi-automatic rename refactoring for JavaScript. In Proc. 28th ACM SIGPLAN Conference on Object Oriented Programming Systems Languages, and Applications, 2013. Google Scholar
Digital Library
- M. Furr and J. S. Foster. Checking type safety of foreign function calls. ACM Transactions on Programming Languages and Systems, 30(4), 2008. Google Scholar
Digital Library
- Google. GWT - JavaScript Native Interface, March 2013. http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html.Google Scholar
- Google. The Dart programming language specification, March 2014. https://www.dartlang.org/docs/spec/.Google Scholar
- S. Guarnieri and V. B. Livshits. Gatekeeper: Mostly static enforcement of security and reliability policies for JavaScript code. In Proc. 18th USENIX Security Symposium, 2009. Google Scholar
Digital Library
- S. H. Jensen, A. Møller, and P. Thiemann. Type analysis for JavaScript. In Proc. 16th International Static Analysis Symposium, 2009. Google Scholar
Digital Library
- K. L. Knowles and C. Flanagan. Hybrid type checking. ACM Transactions on Programming Languages and Systems, 32(2), 2010. Google Scholar
Digital Library
- B. S. Lerner, J. G. Politz, A. Guha, and S. Krishnamurthi. TeJaS: retrofitting type systems for JavaScript. In Proc. 9th Symposium on Dynamic Languages, 2013. Google Scholar
Digital Library
- Microsoft. TypeScript language specification, February 2014. http://www.typescriptlang.org/Content/ TypeScript%20Language%20Specification.pdf.Google Scholar
- M. Polishchuk, B. Liblit, and C. W. Schulze. Dynamic heap type inference for program understanding and debugging. In Proc. 34th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 2007. Google Scholar
Digital Library
- M. Sridharan, J. Dolby, S. Chandra, M. Schäfer, and F. Tip. Correlation tracking for points-to analysis of JavaScript. In Proc. 26th European Conference on Object-Oriented Programming, 2012. Google Scholar
Digital Library
- V. St-Amour and N. Toronto. Experience report: applying random testing to a base type environment. In Proc. 18th ACM SIGPLAN International Conference on Functional Programming, 2013. Google Scholar
Digital Library
- B. Steensgaard. Points-to analysis in almost linear time. In Proc. 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1996. Google Scholar
Digital Library
Index Terms
Checking correctness of TypeScript interfaces for JavaScript libraries
Recommendations
Checking correctness of TypeScript interfaces for JavaScript libraries
OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & ApplicationsThe 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 ...
Type checking and typability in domain-free lambda calculi
This paper shows (1) the undecidability of the type checking and the typability problems in the domain-free lambda calculus with negation, product, and existential types, (2) the undecidability of the typability problem in the domain-free polymorphic ...







Comments