Small Bytes: Putting the Type in TypeScript (Premium)

As a decades-long fan of Anders Hejlsberg and having struggled to see a way forward for Windows desktop apps, I’m understandably curious about TypeScript. Hejlsberg led the development of this free and open-source superset of JavaScript, by far the most popular programming language in the world, specifically to address JavaScript’s biggest problem: its weak type system. That is, where JavaScript is “dynamically typed,” TypeScript is “statically typed.”

So what does that all mean?

First, consider the problem that led to the creation of TypeScript in the first place: Microsoft and its customers wanted to create JavaScript-based web apps at scale, but the syntactically unsophisticated nature of JavaScript made that difficult. After all, JavaScript had been hastily cobbled together by a single person, Netscape’s Brendan Eich, in just 10 days in 1995 and it retains some early design decisions today that see

To its credit, Microsoft at least went about solving this issue correctly, by creating a true superset of JavaScript that didn’t break the compatibility or cross-platform nature of the original language. In other words, a kinder and gentler form of “embrace and extend.”

"TypeScript was really just an idea of, 'Let's see if we can do a little bit better for JavaScript',” Hejlsberg explained in an interview. “The browser wars were over, Google had built Chrome, and HTML5 was happening. Google had also built a very efficient JavaScript engine and the efficiency of JavaScript had gone up tremendously. Everyone was starting to realize that the browser was going to be where real apps were being built.”

The JavaScript of that era lacked lots of sophisticated features like modules, classes, and a type system. Two of them---modules and classes---are part of JavaScript today. And the type system is handled by TypeScript.

“A type system is the ability to check your code before you run and deploy it,” Hejlsberg says. “Without types in a language that's almost impossible. That was really the genesis of TypeScript. The key was to add a type system to the language in a way that doesn't take away all the things that made JavaScript so popular in the first place."

The genius of TypeScript is that it provides type checking while the developer is writing the code in supported IDEs like Visual Studio Code and Visual Studio, and at compile time. But then the TypeScript compiler removes all the types and outputs standard JavaScript code. “It gives you all of the benefits of a type system during the developer experience and none of the drawbacks when you run” the code, Hejlsberg explains.

TypeScript isn’t a panacea for all of JavaScript’s problems. Indeed, there is some debate in the developer community about whether one should even use TypeScript or just stick with JavaScript. But it’s impossible to not be impressed by the accomplishment: TypeScript is a true superset of JavaScript syntactically, b...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC