In complex words, typescript is a syntactic superset of Javascript. In simple words, typescript is built on Javascript's syntax, but it allows developers to add static types. Static typing means that a variable's type can not be changed at any point in the program, unlike javascript. This helps to prevent a lot of bugs.
Pros and Cons of typescript
Here are some of the advantages and disadvantages of typescript:
Advantages:
Typescript code is simpler to debug since type errors can be identified during compile time instead of runtime.
Static typing makes your code easier to refactor and debug.
Typescript allows for better code organizing which improves the readability of your code.
Compatibiity across platforms and browsers: Any device, platform or browser that supports javascript also supports typescript, as far as it is compiled to javascript.
Typescript saves development time, and thus allows developers to be more efficient.
Disadvantages:
Error messages can be difficult to understand.
Increased complexity.
It can take longer time to write and to compile, which may not be suitable for larger projects.
It is only used on the client side, unlike javascript which can be used on both client and server side.
However, since typescript will eventually be compiled into javascript, there's no real risk in choosing either of them.
Getting started with Typescript
To get started using typescript, you need to install it using npm. Assuming you already have node installed, run this command in your command line.
npm install -g typescript
It might bring a permissions error, in which case you have to type sudo in front of the command before running, as shown below:
sudo npm install -g typescript
After this, enter your system's password.
Running this command will allow you to install typescript globally on your machine, instead of installing it whenever you want to use it in a project. This way you can use tsc, which stands for typescript compiler, anywhere in your terminal.
Tsc helps you compile your typescript into javascript to be interpreted and run by the computer.
To confirm that the installation was successful, the following command should return the version of tsc you have installed.
tsc -v