What is TypeScript?

April 15, 2021
3
min read
What is TypeScript?
Thomas Limbüchler
by
Thomas Limbüchler

Since Angular 2 at the latest, TypeScript has been known to many. But what exactly can you do with it, and is it worth changing?

Anyone who has worked with programming languages ​​such as Java or C# before will have noticed that JavaScript allows a surprising amount of freedom, especially when it comes to typing variables or functions. No specifications are expected here to which type a variable should be or which a function should output. This is not necessarily an advantage and, above all, makes it difficult to read and understand the code quickly. This is where TypeScript starts.

The name already reveals the big difference to the usual JavaScript: In TypeScript, types play a role, and then a huge one. Because here, it is standard to provide each variable with a type and type function parameters and outputs in advance. If you then enter a value of the wrong type, an error will be reported immediately.

TypeScript compiler finds your errors

This error message is because you have to compile .ts files, i.e., the TypeScript code, to get actual JavaScript. Of course, these type declarations are missing here, but you will be notified of the error during compilation and then fix it. On the other hand, there is, of course, the additional step of compiling, which is now also necessary for JavaScript in the ES6 variant.

Also important: Even if the compiler shows you errors, a JavaScript file is always created, and this is potentially also executable. This means that TypeScript helps you avoid errors, but in the end, it cannot guarantee that your code is error-free. Unlike Eclipse, for example, the compiler does not prevent you from working with the faulty code.

The code writing itself is pretty straightforward. TypeScript offers a vast number of tooling options such as auto-completion and easy refactoring of your code. The developers have bundled this in support packages with which most common editors can work and thus support TypeScript with all functions. You can even compile directly in Visual Studio.

Otherwise, TypeScript relies on classes. The syntax, which is strongly based on object-oriented programming languages, was definitely very helpful. However, the spelling in JavaScript and TypeScript only separates the typing, which is why the added value is now lower. Otherwise, TypeScript also offers the possibility of modular programming, but the linking must also be done externally by a module loader. TypeScript itself only knows methods for importing and exporting.

Who is TypeScript for?

In the end, TypeScript is just a stricter variant of JavaScript, which will help you if you are working with several people on a project or have to adapt old code from time to time. Then the type declarations increase the readability of your code and make it easier to revise. Of course, for existing projects, this means more work if you want to transfer it to TypeScript, and otherwise, always a little more paperwork. But it can save you from mistakes and force you to think more carefully about your code before you write it down.

If you work with Angular 2, keep in mind that the development team recommends using Angular 2 with TypeScript. And if you have previously worked primarily with object-oriented languages ​​and type declarations, the switch to TypeScript should be much easier than regular JavaScript.

What do you say – is the type declaration of TypeScript a blessing or a curse for you? Or are you looking for a TypeScript job? Check out our job board for TypeScript job offers. 

About the author:
Ready to take charge of your dev career?

Join Europe's leading job platform for software developers!

Register for free

Read more like this