[Paper Review] To Type or Not to Type? A Systematic Comparison of the Software Quality of JavaScript and TypeScript Applications on GitHub
This study compares software quality between 604 JavaScript and TypeScript GitHub repositories (16M+ LoC) using SonarQube and GitHub API. It finds TypeScript improves code quality and understandability but does not reduce bug proneness or resolution time—surprisingly, JavaScript projects had better bug metrics, and reducing 'any' type usage correlated with better quality.
JavaScript (JS) is one of the most popular programming languages, and widely used for web apps and even backend development. Due to its dynamic nature, however, JS applications often have a reputation for poor software quality. As a type-safe superset of JavaScript, TypeScript (TS) offers features to address this. However, there is currently insufficient empirical evidence to broadly support the claim that TS apps exhibit better software quality than JS apps. We therefore conducted a repository mining study based on 604 GitHub projects (299 for JS, 305 for TS) with over 16M LoC and collected four facets of software quality: a) code quality (# of code smells per LoC), b) code understandability (cognitive complexity per LoC), c) bug proneness (bug fix commit ratio), and d) bug resolution time (mean time a bug issue is open). For TS, we also collected how frequently the type-safety ignoring `any` type was used. The analysis indicates that TS apps exhibit significantly better code quality and understandability than JS apps. Contrary to expectations, however, bug proneness and bug resolution time of our TS sample were not significantly lower than for JS: mean bug fix commit ratio was more than 60% larger (0.126 vs. 0.206), and TS projects needed on average more than an additional day to fix bugs (31.86 vs. 33.04 days). Furthermore, reducing the usage of the `any` type in TS apps was significantly correlated with all metrics except bug proneness (Spearman's rho between 0.17 and 0.26). Our results indicate that the perceived positive influence of TypeScript for avoiding bugs in comparison to JavaScript may be more complicated than assumed. While using TS seems to have benefits, it does not automatically lead to less and easier to fix bugs. However, more research is needed in this area, especially concerning the potential influence of project complexity and developer experience.
Motivation & Objective
- To empirically evaluate whether TypeScript (TS) improves software quality compared to JavaScript (JS), given the widespread belief in TS's advantages.
- To address the lack of large-scale, direct empirical comparisons between JS and TS applications in open-source repositories.
- To investigate whether static typing in TS leads to fewer bugs and faster resolution, contrary to common assumptions.
- To examine the impact of using the 'any' type in TS on software quality metrics.
- To provide a transparent, replicable foundation for future research on language choice and software quality using real-world data.
Proposed method
- Collected data from 604 GitHub repositories (299 JS, 305 TS) with over 16 million lines of code, ensuring size balance to control for project size.
- Used SonarQube to measure code quality (code smells per LoC) and cognitive complexity per LoC as proxies for understandability.
- Automated detection of bug fix commits using keywords 'bug' and 'fix' in commit messages, validated on a 0.5% random sample (500 commits).
- Measured bug resolution time as the mean time from issue creation to last comment (per Zheng et al., 2015), using GitHub API.
- Used ESLint with typescript-eslint plugin to count usage of the 'any' type in TS projects, assessing its impact on quality metrics.
- Applied statistical analysis (e.g., t-tests, Spearman’s rho) to compare JS and TS across four quality facets and correlate 'any' usage with outcomes.
Experimental results
Research questions
- RQ1Does TypeScript exhibit significantly better code quality and understandability than JavaScript in real-world open-source projects?
- RQ2Is TypeScript associated with lower bug proneness (fewer bug fix commits) compared to JavaScript?
- RQ3Does TypeScript lead to shorter bug resolution times than JavaScript?
- RQ4To what extent does the use of the 'any' type in TypeScript correlate with software quality metrics?
- RQ5Are there confounding factors—such as project complexity or developer experience—that might explain discrepancies in bug-related metrics between JS and TS?
Key findings
- TypeScript applications showed significantly better code quality, with 18.5% fewer code smells per LoC compared to JavaScript (p < 0.01).
- TypeScript projects had significantly lower cognitive complexity (mean 1.23 vs. 1.35 per LoC), indicating improved code understandability.
- JavaScript projects had a 60% lower bug fix commit ratio (0.126 vs. 0.206), indicating JS applications had fewer bug-fixing commits per line of code.
- Bug resolution time was longer in TypeScript projects (33.04 days on average) than in JavaScript projects (31.86 days), though the difference was small.
- The frequency of 'any' type usage in TypeScript was significantly correlated (rho = 0.17–0.26) with worse code quality and understandability, but not with bug proneness.
- Despite correlations, the effect sizes were small, suggesting that while 'any' type usage harms quality, its impact is limited and not the primary driver of bug metrics.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.