nasrulhazim
5/13/2017 - 6:30 PM

TypeScript in 5 Minutes.

TypeScript in 5 Minutes.

Transpile hello.ts

$ tsc.ts hello.ts

You should have hello.js afterwards

<!DOCTYPE html>
<html lang="en">
    <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="hello.js"></script>
    </head>
    <body>
        <button onclick="sayHello()">Say Hello</button>
    </body>
</html>
class Student {
    fullName: string;
    constructor(public firstName: string, public middleInitial: string, public lastName: string) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
}

interface Person {
    firstName: string;
    lastName: string;
}

function hello(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

function sayHello() {
    var user = new Student("Nasrul", "Hazim", "Mohamad");
    alert(hello(user));
}