An Overview Of Programming Language: TypeScript

Introduction

TypeScript is known to be an open-source programming language that is developed as a superset of JavaScript meaning that any code that is valid in JavaScript is also valuable for TypeScript. Its main objective is to improve the productivity of developing complex applications. 

So it is known to be a syntactic superset of JavaScript that adds static typing. Basically it means that TypeScript adds syntax on top of the JavaScript, allowing the developers to add types.

Therefore, in this article you would be able to get the know-how about this programming language and why it is used by the programmers. Plus if you are a beginner and want to learn the basics about this programming language then you must consider giving this a read. 

Why use TypeScript?

First let’s talk about JavaScript which is a loosely typed language. Plus it can be difficult in order to understand what types of data are being passed around in the JavaScript. 

In JavaScript there are function parameters and variables that don’t have any information. So what developers need to do is that they need to look at the documentation or they have to guess based on the implementation. 

Therefore what TypeScript does is that it allows the specifying types of data to be passed around within the code, including having the ability to report errors when the types fail to match. For example, when passing a string into a function that expects a number TypeScript will suddenly report an error but JavaScript will not. 

That is why many developers use TypeScript as it is quite prompt in making you aware of the error before running the codes when the specified types don’t match by using compile time type checking.

How to use TypeScript?

The most common way of using TypeScript is to use the official TypeScript compiler to transpile TypeScript code into JavaScript. 

Plus there are some popular code editors like Visual Studio Code that have built-in TypeScript support that can show you the errors while you write the codes. 

In order to understand this in the best way possible you could find some tutorials that can help in gaining command over how it is used. Plus TypeScript functions are known to be building blocks that is why it is quite necessary for you to know about them so that you can do things easier while using it.

What Are The Components of TypeScript?

TypeScript is comprised of the following components:

Language: TypeScript language features elements like syntax, keywords, and type annotations. 

TypeScript Compiler: TypeScript compiler (tsc) basically converts the instructions that are written in TypeScript to its JavaScript equivalent. 

TypeScript Language Service: It exposes an additional layer that is around the core compiler pipeline which are editor-like applications. Hence the language service supports the common set of typical editor operations like the statement completions, code formatting and outlining, signature help, and colorization etc.

Declaration Files: Right after when the TypeScript script gets compiled, you can easily find an option in order to generate a declaration file (with the extension .d.ts) that will enable functions as an interface to the components that are compiled in JavaScript. 

The concept of these declaration files is analogous to the concept of header files that is found in C/C++. Therefore, declaration files (files with .d.ts extension) will provide intellisense for  function calls, types, and variable support for JavaScript libraries like jQuery and MooTools etc.

What are the Data Types In TypeScript?

When a variable is created, the intention is to assign some kind of value to that variable but the question arises that what type of value can be assigned to the variable that is dependent upon the datatype of that variable. So in TypeScript the “System” type represents different types of data types that are supported by TypeScript. Following is the classification of Built-in data types that are predined. 

Built-in Data Types:

Following are the built-in data types. Lets see what is the description of these built-in data types:

Boolean: It refers to a system of logical thought that represents true or false.

String: It represents a sequence of characters plus char values and it is also considered as an object.

Number: TypeScript uses numbers to represent both integers as floating point values. 

Void: It is basically used on function return-types. 

Null: This data type is used when an object doesn’t have any value. 

Undefined: It basically denotes value that is given to the uninitialized variable. 

Any: If the variable is declared as any data-type then any type of value can be assigned to that variable. 

Customized Or User-Defined Data Types: 

Apart from having all the built-in data types the user is given the ability to define its own data type. Following are the list of the customized or user-defined data types:

  • Enumerations (enums)
  • Class
  • Interface
  • Array
  • Tuple
  • Function

Conclusion

TypeScript is a programming language that has lots of technicalities but I have compiled the data in the most simple form to give you an overview of what typescript is and what it includes, why it is used and why it is used by the developers. So that you can easily build up an understanding about it.  

Share and Enjoy !

0Shares
0 0