AD World

One of the most significant innovations in web development in the past decade has been the shift towards Typescript. As more and more employers are looking to limit tech debt, learning Typescript is becoming essential to landing a job as a web developer.

While dynamically-typed languages make life easier for the developer in the short run, it can become the reason for unwanted bugs that aren’t caught until runtime. We can avoid this problem with the help of TypeScript. Let’s take a closer look

What is TypeScript?

In the simplest of terms, TypeScript is a superset of JavaScript. This implies that while conventional JavaScript code will work the same in TypeScript, it will also have an extra set of features making our code cleaner and better. TypeScript uses a compiler known as tsc to check for errors in the code and generates(technically known as emitting) the JavaScript equivalent for use in web applications.

TypeScript can also be referred to as a statically typed version of Javascript but we would be overlooking a plethora of other features that TypeScript has to offer. In the next section, we take a look at some of the advantages of using TypeScript.

Advantages of using TypeScript

TypeScript has the following features to offer:

Strong typing – TypeScript places a lot of emphasis on the type of variables being used in the code. If the variable is assigned a value that doesn’t match the type, the TypeScript compiler tsc shows an error.
Object-oriented features – TypeScript introduces a whole lot of object-oriented concepts that help make the code easier to manage.
Compile-time errors – Since there is a compilation step involved, most of the errors get caught at compile time instead of run time.
Emitting with errors – TypeScript will inform the developer about the potential errors in the code but it will make sure to generate the equivalent JavaScript to keep the development process running. The final decision is up to the developer.
Great tooling – TypeScript provides access to a lot of great tools which help in editing, error checking, etc. as you type your code.
Let’s take a look at how we can do that with this simple demo that highlights a few of the above-mentioned features as well.

messages in case of any errors.

The target flag is required to make sure the JavaScript emitted follows the ES2015 standard. By default, tsc emits ES3 standard which is pretty old.

6. If you are using the code given above, it should work straight away. To see TypeScript in action, you need to remove the type annotations. Every time you make a change you need to compile the app.ts again. Changes that don’t conform to TypeScript will generate errors. It will still, however, generate the JavaScript and you can even run it but it might give unexpected results.

We’ve just scratched the surface with what TypeScript has to offer! The biggest thing that you c an do to get more familiar with typescript is begin to use it in your passion projects. The more comfortable you are working with Typescript, the easier time you’ll have using it to write clean code at your company.

Looking for a place to deploy that clean code? Check out Codesphere, the only cloud provider that makes deploying in the cloud as easy as testing locally.

Happy Coding!