skip to main content
research-article

Checking correctness of TypeScript interfaces for JavaScript libraries

Published:15 October 2014Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. M. Furr and J. S. Foster. Checking type safety of foreign function calls. ACM Transactions on Programming Languages and Systems, 30(4), 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Google. GWT - JavaScript Native Interface, March 2013. http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html.Google ScholarGoogle Scholar
  5. Google. The Dart programming language specification, March 2014. https://www.dartlang.org/docs/spec/.Google ScholarGoogle Scholar
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. S. H. Jensen, A. Møller, and P. Thiemann. Type analysis for JavaScript. In Proc. 16th International Static Analysis Symposium, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. K. L. Knowles and C. Flanagan. Hybrid type checking. ACM Transactions on Programming Languages and Systems, 32(2), 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. Microsoft. TypeScript language specification, February 2014. http://www.typescriptlang.org/Content/ TypeScript%20Language%20Specification.pdf.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. B. Steensgaard. Points-to analysis in almost linear time. In Proc. 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Checking correctness of TypeScript interfaces for JavaScript libraries

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 49, Issue 10
      OOPSLA '14
      October 2014
      907 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2714064
      • Editor:
      • Andy Gill
      Issue’s Table of Contents
      • cover image ACM Conferences
        OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications
        October 2014
        946 pages
        ISBN:9781450325851
        DOI:10.1145/2660193

      Copyright © 2014 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 15 October 2014

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!