Top Banner
meetup.com/javascript-israel SUBMIT YOUR LECTURE: facebook.com/groups/jsisrae l http://bit.ly/jsil-apply Thanks To Our Sponsors: SUPPORT THE COMMUNITY: http://bit.ly/jsil-sponsor
29

Getting Started with TypeScript

Mar 20, 2017

Download

Technology

Gil Fink
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with TypeScript

meetup.com/javascript-israel

SUBMIT YOUR LECTURE:

facebook.com/groups/jsisrae

l

http://bit.ly/jsil-apply

Thanks To Our Sponsors:

SUPPORT THE COMMUNITY:

http://bit.ly/jsil-sponsor

Page 2: Getting Started with TypeScript

INTRO TO TYPESCRIPT

LANGUAGE

Gil Fink

sparXys CEO

Page 3: Getting Started with TypeScript

About Me • sparXys CEO and senior consultant

• ASP.NET/IIS Microsoft MVP in the last 7 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 4: Getting Started with TypeScript

Agenda • The Why

• TypeScript Language Features

• Summary

Page 5: Getting Started with TypeScript
Page 6: Getting Started with TypeScript

"JavaScript is the assembly language of the Web"

Erik Meijer

Page 7: Getting Started with TypeScript

“You can write large programs in JavaScript. You

just can’t maintain them”

Anders Hejlsberg

Page 8: Getting Started with TypeScript

JavaScript isn’t Really Bad • JavaScript is really a powerful language:

o Functional

o Dynamic

o Can run everywhere

• Huge community

• Libraries

• Tools

o IDEs

o Debuggers

o Test tools

Page 9: Getting Started with TypeScript

Some Alternatives • We have several alternatives:

• Hard core JavaScript development – my Stockholm syndrome

• JavaScript preprocessors/transpilers

• CoffeeScript – http://coffeescript.org

• Dart – http://dartlang.org

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

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

Page 10: Getting Started with TypeScript

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

compiles to plain JavaScript” ~typescriptlang.org

Page 11: Getting Started with TypeScript

Hello TypeScript

Demo

Page 12: Getting Started with TypeScript

TypeScript is Very Flexible

Any Browser Any Host

Any OS Tools Support

Page 13: Getting Started with TypeScript

Some 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 14: Getting Started with TypeScript

• Modules

• Classes

• Arrow functions

• Default parameters

• Destructuring

• Spread and rest

• Let and const

• for...of

• Object literal

methods

• Shorthand

properties

• Computed

properties

• Octal / binary literals

• Symbols

• Template strings

Features from the near Future of

the Web (ES2015/6), Today

Choose your compilation scenario.

It is up to you!

Page 15: Getting Started with TypeScript

From TypeScript to JavaScript

15

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 16: Getting Started with TypeScript

How Good is TypeScript’s Output?

Page 17: Getting Started with TypeScript

Some Important Side Notes

• All JavaScript code IS TypeScript code

• All JavaScript libraries work with TypeScript

Page 18: Getting Started with TypeScript

Defintely Typed https://github.com/DefinitelyTyped/DefinitelyTyped

Demo

Page 19: Getting Started with TypeScript

TypeScript Type Annotations

• You can add type annotations to variables and

functions

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

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

return ‘hello’ + name;

}

Page 20: Getting Started with TypeScript

TypeScript Types

Page 21: Getting Started with TypeScript

Classes and Interfaces • You can define classes

• You can define interfaces o And implement them later or use to infer typing

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 22: Getting Started with TypeScript

Modules • You define modules to wrap classes, interfaces and

functions

• 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 23: Getting Started with TypeScript

Classes, Modules and Interfaces

Demo

Page 24: Getting Started with TypeScript

Angular 2: Built with TypeScript

• http://blogs.msdn.com/b/typescript/archive/2015/03/05/angular-2-0-built-on-typescript.aspx

• http://blogs.msdn.com/b/visualstudio/archive/2015/03/12/a-preview-of-angular-2-and-typescript-in-visual-studio.aspx

Page 25: Getting Started with TypeScript

TypeScript Versions • TypeScript 1.0 – 1.6

• TypeScript 1.7 o Async/Await for ES6 targets

o Polymorphic this Typing

o ES6 Module Emitting

o ES7 Exponentiation

• Current version: TypeScript 1.8 o Released two days ago (22.2)

Page 26: Getting Started with TypeScript

Questions?

Page 27: Getting Started with TypeScript

Summary • Open source language that compiles into

JavaScript

• Key features: • Code encapsulation

• Maintainable code

• Tooling support

• Learn TypeScript today!

Page 28: Getting Started with 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 29: Getting Started with TypeScript

Thank You!