Highly illogical, Kirk: spotting type mismatches in the large despite broken contracts, unsound types, and too many linters

Joshua Hoeflich, Robert Bruce Findler, Manuel Serrano

Research output: Contribution to journalArticlepeer-review

1 Scopus citations

Abstract

The DefinitelyTyped repository hosts type declarations for thousands of JavaScript libraries. Given the lack of formal connection between the types and the corresponding code, a natural question is are the types right? An equally important question, as DefinitelyTyped and the libraries it supports change over time, is how can we keep the types from becoming wrong? In this paper we offer Scotty, a tool that detects mismatches between the types and code in the Definitely-Typed repository. More specifically, Scotty checks each package by converting its types into contracts and installing the contracts on the boundary between the library and its test suite. Running the test suite in this environment can reveal mismatches between the types and the JavaScript code. As automation and generality are both essential if such a tool is going to remain useful in the long term, we focus on techniques that sacrifice completeness, instead preferring to avoid false positives. Scotty currently handles about 26% of the 8006 packages on DefinitelyTyped (61% of the packages whose code is available and whose test suite passes). Perhaps unsurprisingly, running the tests with these contracts in place revealed many errors in Definitely-Typed. More surprisingly, despite the inherent limitations of the techniques we use, this exercise led to one hundred accepted pull requests that fix errors in DefinitelyTyped, demonstrating the value of this approach for the long-term maintenance of DefinitelyTyped. It also revealed a number of lessons about working in the JavaScript ecosystem and how details beyond the semantics of the language can be surprisingly important. Best of all, it also revealed a few places where programmers preferred incorrect types, suggesting some avenues of research to improve TypeScript.

Original languageEnglish (US)
Article number142
JournalProceedings of the ACM on Programming Languages
Volume6
Issue numberOOPSLA2
DOIs
StatePublished - Oct 31 2022

Keywords

  • Buggy Types
  • Contracts
  • Definitely Typed
  • Gradual Typing
  • TypeScript

ASJC Scopus subject areas

  • Software
  • Safety, Risk, Reliability and Quality

Fingerprint

Dive into the research topics of 'Highly illogical, Kirk: spotting type mismatches in the large despite broken contracts, unsound types, and too many linters'. Together they form a unique fingerprint.

Cite this