Type script = javascript (alomst) done right

Post on 17-May-2015

1.528 views 1 download

Tags:

description

Typescript presentation from the Belgian Visual Studio User Group.

Transcript of Type script = javascript (alomst) done right

TypeScript = JavaScript (almost) done rightMaurice de Beijer

Who am I

Maurice de Beijer

The Problem Solver

Microsoft MVP since 2005

DevelopMentor instructor

Twitter: @mauricedb

Blog: http://msmvps.com/blogs/theproblemsolver/

Web: http://www.HTML5Support.nl

E-mail: Maurice.de.Beijer@gmail.com

Agenda

What is TypeScript?

Why do we need TypeScript?

What is wrong with JavaScript?

TypeScript features

Type annotations

Type inference

Modules

Classes

What is TypeScript?

An open source programming language developed at Microsoft

By Anders Hejlsberg, lead architect of C#

A super set of JavaScript

All JavaScript is valid TypeScript

Adds optional type checking, classes, interfaces and more

Compiles to “normal” JavaScript

Either ECMAScript 5 or ECMAScipt 3

Why do we need TypeScript?

JavaScript was designed for small scripts

These days JavaScript applications get bigger and more complex

Gmail is reported to have 443,000 lines of JavaScript in 2010

This trend will continue

Single Page Applications in the browser

Node.js on the server

Douglas Crockford on TypeScript

Microsoft's TypeScript may be the best of the many JavaScript front ends. It seems to generate the most attractive code. And I think it should take

pressure off of the ECMAScript Standard for new features like type declarations and classes. Anders has shown that these can be provided nicely by a preprocessor, so there is no need to change the underlying

language.

I think that JavaScript's loose typing is one of its best features and that type checking is way overrated. TypeScript adds sweetness, but at a price.

It is not a price I am willing to pay.

Things TypeScript adds to JavaScript

Type annotations

Type inference

Modules

Classes

Interfaces

Based on the ECMAScript 6 proposed standard

Type annotations

Type inference

Type annotations/arrays

Type annotations/param arrays

Arrow functions

Type annotations/casts

TypeScript type definitions

The DOM and standard JavaScript types are provided

Modules

Interfaces

Interfaces

Interfaces & function overloading

Interfaces & type definitions

Classes

Classes & constructors

Classes & constructors

Classes & properties

Arrow functions revisited

Arrow functions revisited

Classes & inheritance

TypeScript is still JavaScript

Not all JavaScript problems are solved by TypeScript

Some older browsers support ECMAScript 3 (December 1999)

Some older browsers have non standard DOM/CSS implementations

jQuery remains an extremely useful library

Conclusion

TypeScript is not perfect

But it helps a lot

You are not forced to use a new language

Leverage existing JavaScript skills en libraries

Consider it for your next “large“ JavaScript project

After all the risk is small