Introduction¶
What is TypeScript?¶
It is a superset of JavaScript programming language that has the concept of static typing to the core feature of JavaScript. This is a big deal because JavaScript is and always has been a dynamic language. TypeScript does not run directly on the browser as JavaScript run, we have to compile the TypeScript file to the JavaScript then it will work as usual.
Dynamic vs. Static¶
DYNAMIC |
STATIC |
---|---|
Types |
Types |
Forgiving |
Rigid |
Great for web browser object modal |
Promotes stability and maintainability |
Example¶
Duck Typing¶
{
name: "duck",
quack: function() {}
function sayQuack(target)
{
target.quack();
}
}
Static Typing¶
class Duck
{
public string name;
public void quack(){}
}
Linux Installation¶
Install Node.js
If you install Node.js, NPM will be automatically installed.
Install the latest version
dev@dev:~$ sudo apt update dev@dev:~$ sudo apt install nodejs dev@dev:~$ node -v v10.19.0
Install specific version
dev@dev:~$ sudo apt update dev@dev:~$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - dev@dev:~$ sudo apt-get install -y nodejs v10.19.0
Remove Node.js and NPM
dev@dev:~$ sudo npm cache clean -f dev@dev:~$ sudo apt-get remove nodejs dev@dev:~$ sudo apt-get remove npm
Go to
/etc/apt/sources.list.d
and remove any node list if you have. Then do an updatedev@dev:~$ sudo apt-get update
Check for any .npm or .node folder in your home folder and delete those. This will give you the location
dev@dev:~$ which node /usr/bin/node
Install NPM
dev@dev:~$ sudo apt install npm
Install TypeScript
dev@dev:~$ sudo npm install -g typescript dev@dev:~$ tsc Version 4.6.3 tsc: The TypeScript Compiler - Version 4.6.3