Mail Web Twitter TypeScript Rainer Stropek software architects gmbh JavaScript on Steroids.

Slides:



Advertisements
Similar presentations
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Advertisements

Building a large scale JavaScript application in TypeScript Alexandru Dima Microsoft.
Validation in Angular 1.3 And other angular tidbits.
The Web Warrior Guide to Web Design Technologies
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Tutorial 10 Programming with JavaScript
Advanced Object-Oriented Programming Features
Using Microsoft SharePoint to Develop Workflow and Business Process Automation Ted Perrotte National Practice Manager, Quilogy, Microsoft Office SharePoint.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
OOP Languages: Java vs C++
NextGen Technology upgrade – Synerizip - Sandeep Kamble.
Philly.NET Hands-on Labs JAVASCRIPT SERIES. July 9: JavaScript Syntax Visual Studio ◦Projects ◦Editors ◦Debugging ◦Script blocks ◦Minification and bundling.
JavaScript Teppo Räisänen LIIKE/OAMK HTML, CSS, JavaScript HTML defines the structure CSS defines the layout JavaScript is used for scripting It.
Eric Vogel Software Developer A.J. Boggs & Company.
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
J AVA S CRIPT Shadi Banitaan 1. O UTLINE Introduction JavaScript Functions Using Objects in JavaScript Built-in Objects User-Defined Objects Examples.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
JavaScript, Fourth Edition
Programming Languages and Paradigms Object-Oriented Programming (Part II)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Tutorial 10 Programming with JavaScript
POS 406 Java Technology And Beginning Java Code
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
OOP IN PHP `Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For.
Introduction to TypeScript Sergey Barskiy Architect Level: Introductory.
An Introduction to Front-end Web Development Tom Perkins.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
What’s New for Web Developers in ASP.NET and Visual Studio 2008 Kate Gregory Microsoft Regional Director
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Programming in Java CSCI-2220 Object Oriented Programming.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
MTA EXAM HTML5 Application Development Fundamentals.
Support standard JavaScript code with static typing Encapsulation through classes and modules Support for constructors, properties and.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
TypeScript : All parts are good Andriy Deren CEO, Onlizer
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
Node.js Modules Header Mastering Node.js, Part 2 Eric W. Greene
Part 1: Overview of LINQ Intro to LINQ Presenter: PhuongNQK.
JavaScript, Sixth Edition
Introduction to TypeScript
Classes (Part 1) Lecture 3
“Under the hood”: Angry Birds Maze
Tutorial 10 Programming with JavaScript
Introduction to Redux Header Eric W. Greene Microsoft Virtual Academy
JavaScript an introduction.
Tutorial 10 Programming with JavaScript
CS5220 Advanced Topics in Web Programming Node.js Basics
CS3220 Web and Internet Programming JavaScript Basics
Lecture 14: JSON and Web SERVICES
Introduction to TypeScript
Presentation transcript:

Mail Web Twitter TypeScript Rainer Stropek software architects gmbh JavaScript on Steroids dotnet Cologne 2013 Saves the day.

Why TypeScript?  JavaScript is great because of its reach JavaScript is everywhere  JavaScript is great because of available libraries For server and client  JavaScript (sometimes) sucks because of missing types Limited editor support (IntelliSense) Runtime errors instead of compile-time errors  Our wish: Productivity of robustness of C# with reach of JavaScript

What is TypeScript?  Valid JavaScript is valid TypeScript TypeScript defines add-ons to JavaScript (primarily type information) Existing JavaScript code works perfectly with TypeScript  TypeScript compiles into JavaScript Compile-time error checking base on type information Use it on servers (with node.js), in the browser, in Windows Store apps, etc. Generated code follows usual JavaScript patterns (e.g. pseudo-classes)  Microsoft provides great tool support E.g. IntelliSense in VS2012

Typing Basics Any Primitive Types Number Boolean String Object Types Classes, Modules, Interfaces, … VS2012 IntelliSense based on types TypeScript – Dotnet Cologne 2013 var n: number; var a;// no type -> Any var s = "Max";// Contextual typing -> string n = 5;// valid because 5 is a number a = 5;// valid because a is of type Any a = "Hello";// valid because a is of type Any n = "Hello";// compile time error because // "Hello" is not a number

What happens with types in JavaScript? Typing Basics Types are used during editing and compiling No type information in resulting JavaScript code Contextual Typing Determine result type from expressions automatically No performance impact TypeScript – Dotnet Cologne 2013

What happens with classes in JavaScript? Typing Basics TypeScript classes become JavaScript pseudo-classes Results in the usual JavaScript pseudo-class pattern TypeScript – Dotnet Cologne 2013

How do modules work? Typing Basics Results in the usual JavaScript module pattern TypeScript – Dotnet Cologne 2013

Language Overview Modules Interfaces TypeScript – Dotnet Cologne 2013 module CrmModule { // Define an interface that specifies // what a person must consist of. export interface IPerson { firstName: string; lastName: string; } … }

Language Overview Classes Note that Person would not need to specify implements IPerson explicitely. Even if the implements clause would not be there, Person would be compatible with IPerson because of structural subtyping. Constructor Note the keyword public used for parameter lastName. It makes lastName a public property. FirstName is assigned manually. Function Type Literal Note the function type literal used for the completeCallback parameter. repository has no type. Therefore it is of type Any. TypeScript – Dotnet Cologne 2013 export class Person implements IPerson { private isNew: bool; public firstName: string; constructor(firstName: string, public lastName: string) { this.firstName = firstName; } public toString() { return this.lastName + ", " + this.firstName; } public get isValid() { return this.isNew || (this.firstName.length > 0 && this.lastName.length > 0); } public savePerson(repository, completedCallback: (bool) => void) { var code = repository.saveViaRestService(this); completedCallback(code === 200); }

Language Overview Derived Classes Note that VipPerson does not define a constructor. It gets a constructor with appropriate parameters from its base class automatically. TypeScript – Dotnet Cologne 2013 // Create derived classes using the "extends" keyword export class VipPerson extends Person { public toString() { return super.toString() + " (VIP)"; }

Language Overview Nested Modules Note that Person would not need to specify implements IPerson explicitly. Even if the implements clause would not be there, Person would be compatible with IPerson because of structural subtyping. TypeScript – Dotnet Cologne 2013 module CrmModule { … // Define a nested module inside of CrmModule export module Sales { export class Opportunity { public potentialRevenueEur: number; public contacts: IPerson[]; // Array type // Note that we use the "IPerson" interface here. public addContact(p: IPerson) { this.contacts.push(p); } // A static member... static convertToUsd(amountInEur: number): number { return amountInEur * 1.3; }

Language Overview Callback functions… TypeScript – Dotnet Cologne 2013 public savePerson(repository, completedCallback: (bool) => void) { var code = repository.saveViaRestService(this); completedCallback(code === 200); } // Call a method and pass a callback function. var r = { saveViaRestService: function (p: CrmModule.Person) { alert("Saving " + p.toString()); return 200; } }; p.savePerson(r, function(success: string) { alert("Saved"); });

Language Overview Structural Subtyping Note structural subtyping here. You can call addContact with any object type compatible with IPerson. TypeScript – Dotnet Cologne 2013 export interface IPerson { firstName: string; lastName: string; } … public addContact(p: IPerson) { this.contacts.push(p); } … import S = CrmModule.Sales; var s: S.Opportunity; s = new S.Opportunity(); s.potentialRevenueEur = 1000; s.addContact(v); s.addContact({ firstName: "Rainer", lastName: "Stropek" }); s.addContact( { firstName: "Rainer", lastName: "Stropek" }); var val = S.Opportunity.convertToUsd(s.potentialRevenueEur);

What happens with interfaces in JavaScript? Interfaces Interfaces are only used for editing and compiling No type information in resulting JavaScript code Structural Subtyping They are gone… TypeScript – Dotnet Cologne 2013

Interfaces Ambient Declarations (.d.ts) External type information for existing JavaScript libraries like JQuery TypeScript Type Definition Library See link in the resources section TypeScript – Dotnet Cologne 2013 interface JQueryEventObject extends Event { preventDefault(): any; } interface JQuery { ready(handler: any): JQuery; click(handler: (eventObject: JQueryEventObject) => any): JQuery; } interface JQueryStatic { (element: Element): JQuery; (selector: string, context?: any): JQuery; } declare var $: JQueryStatic;

Interfaces Ambient Declarations (.d.ts) External type information for existing JavaScript libraries like JQuery TypeScript Type Definition Library See link in the resources section TypeScript – Dotnet Cologne 2013 /// $(document.body).ready(function(){ alert("Loaded"); $("a").click(function(event) { alert("The link no longer took you to timecockpit.com"); event.preventDefault(); });

Shared Code Common Logic… On server (node.js) On client (browser) TypeScript – Dotnet Cologne 2013 export module customer { export interface ICustomer { firstName: string; lastName: string; } export class Customer implements ICustomer { public firstName: string; public lastName: string; constructor (arg: ICustomer = { firstName: "", lastName: "" }) { this.firstName = arg.firstName; this.lastName = arg.lastName; } public fullName() { return this.lastName + ", " + this.firstName; }

Shared Code Node.js Use express.js to setup a small web api. TypeScript – Dotnet Cologne 2013 /// import express = module("express"); import crm = module("customer"); var app = express(); app.get("/customer/:id", function (req, resp) { var customerId = req.params.id; var c = new crm.customer.Customer({ firstName: "Max" + customerId.toString(), lastName: "Muster" }); console.log(c.fullName()); resp.send(JSON.stringify(c)); });

Shared Code Node.js Use express.js to setup a small web api. TypeScript – Dotnet Cologne 2013 app.get("/customer", function (req, resp) { var customers: crm.customer.Customer []; customers = new Array(); for (var i = 0; i<10; i++) { customers.push(new crm.customer.Customer( { firstName: "Max" + i.toString(), lastName: "Muster" })); } resp.send(JSON.stringify(customers)); }); app.use("/static", express.static(__dirname + "/")); app.listen(8088);

Shared Code Browser Uses require.js to load modules at runtime TypeScript – Dotnet Cologne 2013 /// import cust = module("app/classes/customer"); export class AppMain { public run() { $.get(" (data) { var c = new cust.customer.Customer(JSON.parse(data)); $("#fullname").text(c.fullName()); }); }

So What?  TypeScript offers you the reach of JavaScript Stay as strongly typed as possible but as dynamic as necessary  TypeScript makes you more productive (IntelliSense) Ready for larger projects and larger teams  TypeScript produces less runtime errors Because of compile-time type checking  TypeScript can change your view on JavaScript

Resources  Videos, Websites, Documents  TypeScript Type Definition Library  Sample

Mail Web Twitter Q&A Rainer Stropek software architects gmbh Thank You For Coming. Dotnet Cologne 2013 Saves the day.