NL2Type: Inferring JavaScript Function Types from Natural Language Information

By Rabee Sohail Malik, Jibesh Patra, Michael Pradel. 2019

138 citations recorded by the source corpus.

JavaScript is dynamically typed and hence lacks the type safety of statically typed languages, leading to suboptimal IDE support, difficult to understand APIs, and unexpected runtime behavior. Several gradual type systems have been proposed, e.g., Flow and TypeScript, but they rely on developers to annotate code with types. This paper presents NL2Type, a learning-based approach for predicting likely type signatures of JavaScript functions. The key idea is to exploit natural language information in source code, such as comments, function names, and parameter names, a rich source of knowledge that is typically ignored by type inference algorithms. We formulate the problem of predicting types as a classification problem and train a recurrent, LSTM-based neural model that, after learning from an annotated code base, predicts function types for unannotated code. We evaluate the approach with a corpus of 162,673 JavaScript files from real-world projects. NL2Type predicts types with a precision of 84.1% and a recall of 78.9% when considering only the top-most suggestion, and with a precision of 95.5% and a recall of 89.6% when considering the top-5 suggestions. The approach outperforms both JSNice, a state-of-the-art approach that analyzes implementations of functions instead of natural language information, and DeepTyper, a recent type prediction approach that is also based on deep learning. Beyond predicting types, NL2Type serves as a consistency checker for existing type annotations. We show that it discovers 39 inconsistencies that deserve developer attention (from a manual analysis of 50 warnings), most of which are due to incorrect type annotations.

Subfields: Information Systems, Code Generation & Program Synthesis, Program Analysis & Verification, Signal Processing

How researchers see this paper

The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.

In Information Systems

  1. Charles Sutton
  2. Michael Pradel
  3. Miltiadis Allamanis
  4. Prem Devanbu
  5. Arjun Guha
  6. Georgios Gousios
  7. Earl T. Barr
  8. Kevin Jesse

In Code Generation & Program Synthesis

  1. Charles Sutton
  2. Michael Pradel
  3. Miltiadis Allamanis
  4. Koushik Sen
  5. Prem Devanbu
  6. Ge Li
  7. Zhi Jin
  8. Earl T. Barr

In Program Analysis & Verification

  1. Prem Devanbu
  2. Kevin Jesse
  3. Ming-Ho Yee
  4. Arjun Guha
  5. Georgios Gousios
  6. Charles Sutton
  7. Anand Ashok Sawant
  8. Jeffrey S. Foster

In Signal Processing

  1. Michael Pradel
  2. Prem Devanbu
  3. Georgios Gousios
  4. Kevin Jesse
  5. Charles Sutton
  6. Toufique Ahmed
  7. Koushik Sen
  8. Ge Li

Citations in the corpus