news
JavaScript survey: developers want static typing (and prefer TypeScript over vanilla JS)
The latest State of JavaScript survey confirms findings from previous editions. Developers love and want static typing in very popular programming languages. Additionally, you are 100% more likely to use statically typed TypeScript than dynamically typed vanilla JavaScript.
Typing has long been a point of contention in the sprawling Lucy Goose JavaScript language. The JavaScript language has been considered the most popular programming language in many surveys, despite creating a love-hate schism not seen in most other technology offerings.
The preference for more structured, statically typed JavaScript code has led to the rise of Microsoft’s TypeScript language, which has steadily grown in popularity over the years. For example, TypeScript is listed as the 4th most used language in the State of the Octoverse report on GitHub. It also recently leapfrogged Java to crack the top five languages in the usage statistics of Stack Overflow’s giant annual developer survey.
2022-5
2021-7
2020-9
2019-10
2018-12
Additionally, TypeScript is listed in both the top 4 most loved languages since 2017 and the 10 most used languages in Stack Overflow’s research series.
Note, however, that JavaScript is still at the top of that list, as it has been over the years on SO and other research series.
However, the new 2022 State of JavaScript survey shows strong demand for static typing, with more respondents using TypeScript 100% of the time (about 21%) than those using JavaScript 100% of the time. Contains one chart showing a high percentage. (about 8 percent).
but why? One of the main attractions of static typing is improved debugging and handling of type errors. “Statically typed languages such as Java, Go, and C++ can detect type-related errors at compile time,” explains his SE-EDU site (a resource for software engineering education). “However, in dynamically typed languages such as Python, Ruby, and JavaScript, the type of variables is known only at runtime, so such errors are not easily discovered.”
In the latest State of JavaScript survey, it’s clear that detecting errors at compile time is a developer’s preference. This research is conducted by Sacha Greif and Eric Burel with the support of a team of open source contributors and consultants.
Case in point: When developers were asked what they felt was missing in JavaScript, “static typing” was by far the top answer, given by 15,363 respondents, followed by “the standard library was mentioned by 12,929 respondents. His last three years in the investigative series have been like that.
To satisfy that long-standing desire, Microsoft’s TypeScript isn’t the only product offering static typing capabilities. As explained on his SE-EDU site, Flow is another prominent member of that camp.
“In the JavaScript community, Flow and TypeScript have emerged as the two main options for enabling static type checking,” offers this comparison.
- Flow is a static type checker for JavaScript. It is an open source tool developed by Facebook.
- TypeScript is a statically typed superset of JavaScript that compiles to plain JavaScript. An open source programming language developed by Microsoft.
“Flow and TypeScript are integrated into development workflows in slightly different ways, but they have the same goals and share many syntactical similarities,” the SE-EDU article continues. “As the industry seems to be moving his TypeScript to the top choice (source), in this article he will show you how TypeScript works and how to get started with it.”
And beyond TypeScript and Flow, there are many other JavaScript typing initiatives, with the first result of a web search for “JavaScript typing” being Typed JavaScript, “a system of tools and practices that expose type errors before execution. ” is explained. Optional, typed JavaScript runs where JavaScript runs without modification. Typed JavaScript provides static type checking, without compilers or special tools. Use typed JavaScript as much as you like You can. If it doesn’t work, it’s easy to change it back. ”
Microsoft has also tackled this problem in ways other than TypeScript, writing a Proposal for Type Syntax in JavaScript last March.
In explaining how it works, a post by Microsoft’s Daniel Rosenwasser states:
When asked, “When will types be added to JavaScript?”, we had to hesitate to answer. Historically, the problem has been that when you ask developers what they think of types in JavaScript, you get a wide variety of answers. Some felt that types should be ignored entirely, while others felt they should have some meaning. Perhaps it should enforce some kind of runtime verification, should be introspectable, should act as a hint to the engine for optimization, etc. , more! But over the last few years, I’ve seen people converge on the direction that TypeScript is headed: complete ignorance of types at runtime, erasable syntax and a design that works well. This convergence, alongside the widespread use of TypeScript, made us more confident when a few JavaScript and TypeScript developers outside our core team approached us again with a proposal called “types as comments”. It made me feel like holding it.
The idea of this proposal is that JavaScript can open up a set of syntaxes for types that engines do. Ignore completelybut what tools can I use like TypeScript, Flow, and others. can be eliminated.
Rosenwasser’s link points to a proposal to add type annotations to the official JavaScript standard, ECMAScript, and the GitHub project description states:
This proposal is intended to allow developers to add type annotations to their JavaScript code. Outside JavaScriptAt runtime, the JavaScript engine ignores them and treats the types as comments.
The purpose of this proposal is to allow developers to run programs written in TypeScript, Flow, and other statically typed supersets of JavaScript without the need for transpilation.
The proposal points out that static typing was also the most requested language feature in the State of JavaScript 2020 and 2021 survey, as shown in the diagram above.
Overall, the 2022 report shows that the JavaScript camp is happy, with nearly 47% of respondents satisfied with the overall state of the language. The biggest pain point is the “code architecture”, which may be related to the lack of static typing capabilities. In that regard, “JavaScript and TypeScript are more vibrant than ever,” says the report. “We saw a continuation of performance-leading innovations in responsiveness and hydration (or lack thereof).”
The survey will be conducted from November 21st to December 22nd, 2022 and received 39,472 responses.
About the author
David Ramel is an editor and writer at Converge360.