About TypeScript is an open-source language and compiler that runs both in the browser -through SystemJS and on NodeJS.
Is developed by Microsoft, like an open-source language and compiler that runs both in the browser through SystemJS and on NodeJS.
Now TypeScript compiles to clean, simple JavaScript code.
You can runs on any browser, in Node.js, or in any JavaScript engine that supports ECMAScript 3 (or newer).
There are two main ways to get TypeScript tools:
- using npm (the Node.js package manager)
- or installing TypeScript’s Visual Studio plugins
The easiest way to get started with TypeScript is through the TypeScript playground found on the TypeScript website play.
The TypeScript version 2.4 has already introduced dynamic import expressions, safer callback parameter checking, weak types, and string enums.
About dynamic import expressions then allow users to asynchronously request a module at any arbitrary point in your program.
The string enums allow enum members to contain string initializers.
Allow to return types as inference targets can now make inferences for the return type of a call.
To get started with the latest stable version of TypeScript, you can grab it through NuGet with:
1 | PM> Install-Package Microsoft.TypeScript.Compiler |
You can use the following command with npm:
1 | npm install -g typescript |
You can download it from the official website.
To compile it use this:
1 | tsc helloworld.ts |
Now, let’s install it and try it.
First use git command to put into your computer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | C:\>npm install -g typescript C:\Users\mythcat\AppData\Roaming\npm\tsc -> C:\Users\mythcat\AppData\Roaming\npm\node_modules\typescript\bin\tsc C:\Users\mythcat\AppData\Roaming\npm\tsserver -> C:\Users\mythcat\AppData\Roaming\npm\node_modules\typescript\bin\tsserver C:\Users\mythcat\AppData\Roaming\npm `-- typescript@2.4.2 C:\>tsc -version Version 2.4.2 C:\>mkdir ts001 C:\>cd ts001 C:\ts001>notepad ts_es001.ts C:\ts001>tsc ts_es001.ts C:\ts001>dir Volume in drive C is free-tutorials Volume Serial Number is 0EB1-091D Directory of C:\ts001 08/09/2017 07:42 PM <dir> . 08/09/2017 07:42 PM <dir> .. 08/09/2017 07:42 PM 54 ts_es001.js 08/09/2017 07:42 PM 51 ts_es001.ts 2 File(s) 105 bytes 2 Dir(s) 771,618,115,584 bytes free |
Make a file named ts_es001.ts and use this command:
1 | C:\ts001>tsc ts_es001.ts |
The result will be ts_es001.js file.
Create your ts_es001.html file with this content:
1 2 3 4 5 6 7 | <!DOCTYPE html> <html> <head><title>TypeScript Greeter</title></head> <body> <script src="ts_es001.js"></script> </body> </html> |
This is the most simple example of using typescript tool with node.js.