Introduction
In this article we are going to learn TypeScript. Definition of TypeScript its purpose and also a simple “Hello World” example.
What is TypeScript?
It is a programming language which was developed by Microsoft. It provides supports for object-oriented programming and optional static typing. It is mainly used for creating large applications where it always compiles into JavaScript.
It can be used to develop JavaScript applications for both client side and server side. TypeScript is a superset of ES5, and it has more feature for ES6. It comes with concepts such as:
Installing TypeScript:
There are two ways to install TypeScript into our system. These are as follows:
Hello World Example
In this example, we are going to use Visual Studio 2012 with TypeScript plugins installed. Following are the steps for creating TypeScript application in Visual Studio 2012 as follows:
You can see above screenshot after selecting the TypeScript from left side template, in the right side you can see the template 'HTML Application with TypeScript'.
app.ts
window.onload = () => {
var msg = document.getElementById('jeet');
msg.innerHTML = "Hello World from TypeScript!";
};
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>First TypeScript Application</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="app.js"></script>
</head>
<body>
<div id="jeet"></div>
</body>
</html>
After building the application the TypeScript compiler creates a '.js' file for same just open the 'app.js' file and see code as below:
window.onload = function () {
var msg = document.getElementById('content');
msg.innerHTML = "Hello World from TypeScript!";
};//# sourceMappingURL=app.js.map
Great, our first TypeScript application is successful!
Summary
I hope that you understand concept of TypeScript with example. If you have any suggestion regarding this article, then please comment below. Stay tuned for other TypeScript concepts!
Thanks for reading. Learn it! Share it!