about 8 years ago
Typescript is Microsoft’s extension of Javascript. It provides type checking abilities and also has features of object oriented programming. TypeScript is used in both Angular2 and Ionic2.
TypeScript has similar syntax and semantics that are used in javascript by developers.
Installing TypeScript
You can install TypeScript tools in two ways:
Run the following command to install TypeScript:
Build TypeScript File:
Write the following code in your text editor and save it as hello.ts :
Compile the code:
Run this TypeScript compiler tsc greeter.ts
It will create a greeter.js file with the same javascript code that is written in ts file.
Type annotations:
There are some ways in TypeScript that can be used to record the intended contract of the variable or function. Here, we are passing string as a parameter in hello function:
here we have added :string type annotation to hello function as argument.
Running your TypeScript web app:
Now create a html file hello.html with the below code and run it in browser to see the result.
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)