Type script = javascript (alomst) done right

30
TypeScript = JavaScript (almost) done right Maurice de Beijer

description

Typescript presentation from the Belgian Visual Studio User Group.

Transcript of Type script = javascript (alomst) done right

Page 1: Type script = javascript (alomst) done right

TypeScript = JavaScript (almost) done rightMaurice de Beijer

Page 2: Type script = javascript (alomst) done right

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: [email protected]

Page 3: Type script = javascript (alomst) done right

Agenda

What is TypeScript?

Why do we need TypeScript?

What is wrong with JavaScript?

TypeScript features

Type annotations

Type inference

Modules

Classes

Page 4: Type script = javascript (alomst) done right

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

Page 5: Type script = javascript (alomst) done right

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

Page 7: Type script = javascript (alomst) done right

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.

Page 8: Type script = javascript (alomst) done right

Things TypeScript adds to JavaScript

Type annotations

Type inference

Modules

Classes

Interfaces

Based on the ECMAScript 6 proposed standard

Page 9: Type script = javascript (alomst) done right

Type annotations

Page 10: Type script = javascript (alomst) done right

Type inference

Page 11: Type script = javascript (alomst) done right

Type annotations/arrays

Page 12: Type script = javascript (alomst) done right

Type annotations/param arrays

Page 13: Type script = javascript (alomst) done right

Arrow functions

Page 14: Type script = javascript (alomst) done right

Type annotations/casts

Page 15: Type script = javascript (alomst) done right

TypeScript type definitions

The DOM and standard JavaScript types are provided

Page 17: Type script = javascript (alomst) done right

Modules

Page 18: Type script = javascript (alomst) done right

Interfaces

Page 19: Type script = javascript (alomst) done right

Interfaces

Page 20: Type script = javascript (alomst) done right

Interfaces & function overloading

Page 21: Type script = javascript (alomst) done right

Interfaces & type definitions

Page 22: Type script = javascript (alomst) done right

Classes

Page 23: Type script = javascript (alomst) done right

Classes & constructors

Page 24: Type script = javascript (alomst) done right

Classes & constructors

Page 25: Type script = javascript (alomst) done right

Classes & properties

Page 26: Type script = javascript (alomst) done right

Arrow functions revisited

Page 27: Type script = javascript (alomst) done right

Arrow functions revisited

Page 28: Type script = javascript (alomst) done right

Classes & inheritance

Page 29: Type script = javascript (alomst) done right

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

Page 30: Type script = javascript (alomst) done right

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