TypeScript
Nitay Neeman
https://goo.gl/jj5K7x
We will talk about
○ What is TypeScript?
○ Motivation
○ Brief history
○ Main features
○ Conclusions
2
What is TypeScript?
“TypeScript is a free and open source programming
language developed and maintained by Microsoft.
It is a strict superset of JavaScript, and adds optional
static typing and class-based object-oriented
programming to the language.” (Definition by Wiki)
TypeScript transpiles to pure JavaScript.
3
The meaning of transpiling
Compilation - taking source code written in one
language and transforming into another.
For example: C# -> IL.
Transpilation - taking source code written in one
language and transforming into another language
that has a similar level of abstraction.
For example: C++ -> C, Sass / LESS -> CSS.
4
Motivation
○ Syntax checking
○ Code completion
○ Type annotations
○ ES6 support
○ Help us preparing for AngularJS 2.0
5
Brief history
○ 2010 - Microsoft started internal development.
○ 2012 - First release (0.8) of TypeScript.
It was supported in Visual Studio only.
○ 2013 - Next release (0.9) for supporting other IDE’s.
○ 2014 - TypeScript 1.0 was released.
Meanwhile, AtScript was announced by Google.
○ 2015 - Microsoft and Google announced that AtScript
development was abandoned and that features of
AtScript would be implemented in TypeScript. 6
The reaction of Microsoft about AtScript..
7
TypeScript and ECMAScript 6
8
So.. TypeScript includes:
○ Classes
○ Modules
○ Arrow functions
○ Default, optional and rest parameters
And all the awesome features of ES6!
9
New basic types
○ Boolean
○ Number (float)
○ String
○ Array (one type)
○ Enum
○ Any - general type
○ Void - empty type
10
Syntax checking
The following command:
Transpilation output:
11
Interfaces
Interfaces define rules on following types:
○ Objects
○ Functions
○ Arrays
○ Classes
12
Interfaces - Objects
13
Interfaces - Functions
14
Interfaces - Classes
15
Generics
General types for reusability.
16
Generics - Classes
17
Generics - Constraints
18
Mixins
Build a class by partial classes.
19
Declaration Merging
Merging of:
○ Multiple interfaces
○ Multiple modules
○ Modules with:
○ Classes
○ Functions
○ Enums
20
Declaration Merging - Interfaces
The following are equal:
21
Declaration Merging - Modules
In similar way, the following are equal:
22
Declaration Merging - Modules & Classes
Exporting of module members into a class:
23
Declaration Merging - Modules & Enums / Functions
In the same way,
24
Module
- Members
Enum
Enum object with static
members
Function
Function object with
static members
Declaration file (.d.ts)
Without this file - TypeScript transpiler will not
recognize the code of external JavaScript library.
Actually, it guides the transpiler how to structure the
code and it provides the desired “type annotation”.
Download or build your own.
25
Resources
○ TypeScript Definition
○ Compiling vs Transpiling
○ AtScript History
○ Declaration file
○ TypeScript Handbook
○ TypeScript Playground
26
Questions
27
?

Why do we need TypeScript?