T

Table of Contents

    ypeScript 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

    176 posts

    Founder of Scotch.io. Google Developer Expert in Web Technologies. Slapping the keyboard until something good happens.