mudularity and unit testing in typescript (for ng-bkk #3)

33
MODULARITY AND UNIT TESTING IN TYPESCRIPT Suthep Sangvirotjanaphat Founder and Instructor of GreatFriends.biz Microsoft Most Valuable Professional

Upload: suthep-sangvirotjanaphat

Post on 17-Aug-2015

147 views

Category:

Technology


1 download

TRANSCRIPT

MODULARITY AND UNIT TESTING

IN TYPESCRIPTSuthep SangvirotjanaphatFounder and Instructor of GreatFriends.biz

Microsoft Most Valuable Professional

hi

GreatFriends

■ Page fb.com/greatfriends.biz

■ Group fb.com/groups/greatfriends.biz

■ Web next.greatfriends.biz

■ Me fb.com/suthep

Other FB Groups

■ F# Thai

■ TypeScript Thailand

■ git ฮั�บ และ มื�อใหมื�Gitฮั�บ■ .NET Framework Source Code Study Group

TypeScript

Features from the future,

today.

■ 0.8

■ 1.0

■ 1.3

■ 1.4

■ 1.5

■ 1.6

■ 2.0

TYPESCRIPTTypeScript is a superset of JavaScript

that compiles to clean JavaScript output.

TypeScript

DefinitelyTyped and tsd

■ http://definitelytyped.org

■ http://definitelytyped.org/tsd

Lang. ■ Types

■ Classes

■ Interfaces

■ Generics

Type annotation

var x : number;

x = true; // error

x = 100; // ok

function print(s : string) : void {

console.log(s);

}

print(x); // error

print(x.toString()); // ok

Type inference

var x = 10; // infer x as a number

var x : number = 10;

// infer this function return type as string

function Foo(n: number) { return n.toFixed(2); }

function Foo(n: number) : string { … }

Basic types

boolean // var b = true, c = false;

number // var n = 100, m = 10.0;

string // var s = 'Hello';

array // var a1: number[] = [ 1, 3, 5 ];array // var a2: Array<number> = [ ];

enum // var c = Color.red;

any // var x;

void // foo(): void { }

Class

Interface and duck typing

Arrow functions

Using TypeScript with AngularJS

Demo 1 of 3

■ Install typescript

■ Coding and compiling

■ Install tsd

■ Install definition files from 3rd party libraries

TypeScript1.5

■ Lots of ES 6 language features

■ Modules

■ Decorators

ES 6 language features

■modules

■destructing

■spread

■for..of

■computed properties

■let/const

■tagged string template

Decorators■ needs --experimentalDecorators compiler option

TypeScript Internal Modules

External Modulesimport and export

commonjs and amd

umd

import statement

Demo 2 of 3

■ Kafi Project

■ Live Demo

kafi.azurewebsites.netgithub.com/surrealist/kafi

Kafi (class model)

Unit Testingwith

mochaand chaimochajs.org

chaijs.com

mocha

Demo 3 of 3

■ unit testing in TypeScript

More resources about TypeScript

http://facebook.com/groups/typescript.thailand

http://www.typescriptlang.org

http://www.typescriptlang.org/Handbook

http://blogs.msdn.com/b/typescript

http://definitelytyped.org

http://definitelytyped.org/tsd

https://github.com/microsoft/typescript

https://github.com/microsoft/typescript/wiki

Q&AMore fun ahead! please visit and join GreatFriends!

■ Page fb.com/greatfriends.biz

■ Group fb.com/groups/greatfriends.biz

■ Web next.greatfriends.biz

■ Me fb.com/suthep