end-to-end spa development using typescript

20
BUILDING END-TO-END SPA USING TYPESCRIPT Gil Fink sparXys CEO

Upload: gil-fink

Post on 05-Aug-2015

182 views

Category:

Software


1 download

TRANSCRIPT

Page 1: End-to-End SPA Development using TypeScript

BUILDING END-TO-END

SPA USING TYPESCRIPT

Gil Fink

sparXys CEO

Page 2: End-to-End SPA Development using TypeScript

About Me • sparXys CEO and senior consultant

• ASP.NET/IIS Microsoft MVP in the last 6 years

• Pro Single Page Application Development (Apress)

co-author

• 4 Microsoft Official Courses (MOCs) co-author

• GDG Rashlatz and ng-conf Israel co-organizer

Page 3: End-to-End SPA Development using TypeScript

Agenda • TypeScript?

• Building a Simple App with TypeScript

• Summary

Page 4: End-to-End SPA Development using TypeScript

Wait! End to end JavaScript?

Are you nuts?

Page 5: End-to-End SPA Development using TypeScript

"JavaScript is the assembly language of the Web"

Erik Meijer

Page 6: End-to-End SPA Development using TypeScript

“You can write large programs in JavaScript. You

just can’t maintain them”

Anders Hejlsberg

Page 7: End-to-End SPA Development using TypeScript

Some Alternatives • We have several alternatives:

• Hard core JavaScript development

• JavaScript preprocessors

• CoffeeScript – http://coffeescript.org

• Dart – http://dartlang.org

• Clojurescript - https://github.com/clojure/clojurescript

• Script# - http://scriptsharp.com/

Page 8: End-to-End SPA Development using TypeScript

What is TypeScript? “TypeScript is a typed superset of JavaScript that

compiles to plain JavaScript” ~typescriptlang.org

Page 9: End-to-End SPA Development using TypeScript

Hello TypeScript

Demo

Page 10: End-to-End SPA Development using TypeScript

TypeScript Key Features

Support standard

JavaScript code with

static typing

Encapsulation through classes

and modules

Support for constructors,

properties and functions

Interfaces and enums support

Lambda and generics support

Intellisense and syntax checking

Page 11: End-to-End SPA Development using TypeScript

From TypeScript to JavaScript

11

class Greeter {

greeting: string;

constructor(message: string) {

this.greeting = message;

}

greet() {

return “Hi," + this.greeting;

}

}

TypeScript Code JavaScript Code

TypeScript Compiler

var Greeter = (function () { function Greeter(message) { this.greeting = message; } Greeter.prototype.greet = function () { return “Hi," + this.greeting; }; return Greeter; })();

tsc.js

Page 12: End-to-End SPA Development using TypeScript

TypeScript Type Annotations

• You can add type annotations to variables and

functions

12

var str: string = ‘hello’; // str is annotated as string

function foo(name: string) : string { // parameter and function annotated

return ‘hello’ + name;

}

Page 13: End-to-End SPA Development using TypeScript

Classes and Interfaces • You can define classes

• You can define interfaces o And implement them later

interface IGreeter {

greet(): void;

}

class Greeter implements IGreeter{

greeting: string;

greet() {

console.log(this.greeting);

}

}

var Greeter = (function () {

function Greeter() {

}

Greeter.prototype.greet = function () {

console.log(this.greeting);

};

return Greeter;

})();

Page 14: End-to-End SPA Development using TypeScript

Modules • You define modules to wrap classes, interfaces and

functionality

• Use import and export keywords

• module app {

export interface IGreeter {

greet(): void;

}

export class Greeter implements IGreeter {

greeting: string;

greet() {

console.log(this.greeting);

}

}

}

var app;

(function (app) {

var Greeter = (function () {

function Greeter() {

}

Greeter.prototype.greet = function () {

console.log(this.greeting);

};

return Greeter;

})();

app.Greeter = Greeter;

})(app || (app = {}));

Page 15: End-to-End SPA Development using TypeScript

Classes, Modules and Interfaces

Demo

Page 16: End-to-End SPA Development using TypeScript

Building a Simple End-to-End App with TypeScript

Demo

Page 17: End-to-End SPA Development using TypeScript

Questions?

Page 18: End-to-End SPA Development using TypeScript

Summary • Open source language that compiles into

JavaScript

• Key features: • Code encapsulation

• Maintainable code

• Tooling support

• Learn TypeScript today!

Page 19: End-to-End SPA Development using TypeScript

Resources • TypeScript – http://www.typescriptlang.org

• TypeScript Source Code -

https://github.com/Microsoft/TypeScript

• Definitely Typed –

https://github.com/borisyankov/DefinitelyTyped

• My Website – http://www.gilfink.net

• Follow me on Twitter – @gilfink

Page 20: End-to-End SPA Development using TypeScript

Thank You!