Introduction to TypeScript

Learn about TypeScript, a superset of JavaScript that adds extra features.

What is TypeScript?

So, what exactly is TypeScript? And how can we use it? Well, it really is as simple as “TypeScript generates JavaScript,” to quote Anders Hejlsberg, the designer of the TypeScript language. Wherever we see a use for JavaScript in the modern world, we can generate this JavaScript using TypeScript. In simple terms, TypeScript is a superset of JavaScript. It includes all of the features of JavaScript and adds a few additional features.

JavaScript is being used everywhere—the more we look, the more JavaScript we find running in the most unlikely of places. Just about every website that we visit uses JavaScript to make the site more responsive, more readable, or more attractive to use.

The power and flexibility of JavaScript also mean that more and more tools are moving online. Where we once needed to download and install a program to write a document or draw a diagram, we can now do this all from within the confines of our humble web browser.

Why we need TypeScript

The popularity and simplicity of JavaScript have inspired a whole host of runtime environments that can now run on a server, through Node.js (or simply Node), in the cloud through serverless technologies, or even on embedded devices with purpose-built microcontroller chips.

Apache Cordova is a fully-fledged web server that runs as a native mobile phone application, meaning that JavaScript, HTML, and CSS can be used to create mobile applications. Even desktop applications can be built using JavaScript, such as the popular editors Visual Studio Code and Atom. These desktop projects use the Electron framework and, as such, are fully-fledged desktop applications that can run on Windows, macOS, or Linux.

We can see that JavaScript is a powerful and widely used language that can run in a variety of runtime environments, including servers, the cloud, and even embedded devices. However, as applications become larger and more complex, the flexibility and simplicity of JavaScript can also present challenges. This is where TypeScript comes in—by adding additional features and benefits on top of JavaScript, it can help developers write maintainable, scalable code more efficiently and address common challenges that arise in large-scale JavaScript development.

Press + to interact

Building JavaScript applications, therefore, means that what we build could be run on just about any operating system, use any architectural framework, or be used in any embedded device.

It is in the building of these JavaScript applications where TypeScript comes into its own. JavaScript is an interpreted language, and as such has benefits but also drawbacks. Interpreted languages do not have a compilation step and therefore can’t check that all code written has no minor mistakes in spelling or syntax before it is actually run. TypeScript is a strongly typed, object-oriented language that uses a compiler to generate JavaScript. The compiler will identify errors within the code base even before it is run in an interpreter.