Migrating from JavaScript to TypeScript

[Pages:15]Migrating from JavaScript to TypeScript

TypeScript. JavaScript that scales.

Seungjae Lee @huiseoul

Huiseoul?

Frontend React Native, Mobx ...

Backend Node.js, GraphQL ...

Written by TyoeScript and one @types/huiseoul

History

2012 10 MicroSoft

2014 4 Build v1.0 VS2013 builtin

2014 7 5 , Github

2016 9 v2.0 @types/* strictNullChecks

v2.3.2

Specs

Opensource: Superset of JavaSript

JavaScript

Static Typing Checked at compile time Type annotation

OOP EcmaScript features

supports v3 ~ future proposals ... and much more

Benefit

: OK : >

Learning curve

JavaScript JavaScript !

Install & run

$ npm install -g typescript $ echo 'console.log("Hello, World!");' > saystone.ts $ tsc saystone.ts $ node saystone.js Hello, World!

Compiler config

your-project/tsconfig.json

# automically points ./your-project/tsconfig.json your-project$ tsc

json.html

Example: Pure TypeScript

class Student { fullName: string; constructor(public firstName, public middleInitial, public this.fullName = firstName + " " + middleInitial + }

}

interface Person { firstName: string; lastName: string;

}

function greeter(person : Person) { return "Hello, " + person.firstName + " " + person.lastName

}

var user = new Student("Jane", "M.", "User");

console.log(greeter(user));

Output: Converted JavaScript

var Student = (function () { function Student(firstName, middleInitial, lastName) { this.firstName = firstName; this.middleInitial = middleInitial; this.lastName = lastName; this.fullName = firstName + " " + middleInitial + } return Student;

}()); function greeter(person) {

return "Hello, " + person.firstName + " " + person.lastName } var user = new Student("Jane", "M.", "User"); console.log(greeter(user));

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download