Video Course

Getting Started with Angular v4: Lesson 5 of 26

TypeScript Fun

Up Next

Angular Dependencies

Autoplaying in 7 seconds!

Cancel

Create a Free Account to Watch

Sign Up Now

Login to your account

TypeScript allows us to write really clean code that will compile down to ES5 and be supported by our browsers. Even if you didn't want to use all the TypeScript features, you could use it mainly as a transpiler and stick to vanilla JS.

Here's some cool things TypeScript can do for us:


// typescript
class Greeter {}

// javascript
var Greeter = (function() {
    function Greeter() {}
    return Greeter;
}());

// ==================================

// es6
const message = 'hello';

// javascript
var message = 'hello';

// =================================

// typescript
function saySomething(message = 'default message') {}

// javascript
function saySomething(message) {
  if (message === void 0) { message = 'default message'; }
}

// =================================

// es6
const username = 'chris';
const message = `Say hello to ${username}`;

// javascript
var username = 'chris';
var message = "Say hello to " + username;

Chris Sevilleja

157 posts

Co-founder of Scotch.io. Slapping the keyboard until something good happens.