• For example: //Typescript class Test { //field name:string; //constructor constructor(name:string) { this.name = name } //function display_name():void { console.log(“name is : “+this.name) } } //javascript var Test = (function () { //constructor function Test(name) { this.name = name; } //function Test.prototype.display_name = function () { console.log(“name is : “ + this.name); }; return Test; }()); In the snippet above, notice that it is easier to read the TypeScript version of the code than the JavaScript Version.
  • Getting Started To install TypeScript globally so you can call it when needed, run: npm install -g typescript For verification of the installed TypeScript, use the tsc — v command: tsc — v //Version 2.1.6 Next, install gulp for the build process.
  • To do that, we run: npm install gulp gulp-typescript typescript — save Doing just this setup done might be enough, but you would have to go back to the terminal to run the tsc command every time a change occurs.
  • Now, put the following contents into the gulpfile.js: const gulp = require(‘gulp’); const ts = require(‘gulp-typescript’); // pull in the project Typescript config const tsProject = //task to be run when the watcher detects changes gulp.task(‘scripts’, () = { const tsResult = tsProject.src() .
  • const server = http.createServer(App); server.listen(port); server.on(‘listening’, onListening); //function to note that Express is listening function onListening(): void { console.log(`Listening on port `+port); } This has imported the HTTP module from node.

Read more


@palashv2: “🔥 How to use #TypeScript with #Node: #Angular #javascript #100DaysOfCode #es6 #npm #vuejs #reactjs #CodeNewbie” open tweet »