SlideShare a Scribd company logo
Aniruddha Chakrabarti
Sr. Principal Architect & Sr. Manager, Accenture
caniruddha@hotmail.com | in.linkedin.com/in/aniruddhac
Context
• Writing large applications in JavaScript is difficult, not originally designed
for large complex applications (mostly a scripting language, with
functional programming constructs)
• Lacks structuring mechanisms like Class, Module, Interface
TypeScript is a language for application scale JavaScript
development.
TypeScript is a typed superset of JavaScript that compiles to
plan JavaScript.
TypeScript adds Static Typing and structuring (class, module) to JavaScript.
Fix/Improve JavaScript – different approaches
1. Through Library and Frameworks
– jQuery, AngularJS, Knockout, Ext JS, Bootstrap …. (new libraries are being
created and getting popular everyday)
2. New language that extend/improve language features of JavaScript.
Superset of JavaScript. Compiles to JavaScript
– CoffeeScript, TypeScript
3. Entirely new language with many new features that compile to
JavaScript
– GWT (Google Web Toolkit), Dart
https://github.com/jashkenas/coffeescript/wiki/list-of-languages-that-compile-to-js
What is TypeScript
• Helps in large scale JavaScript application development.
• Adds additional features like Static Type (optional), Class, Module etc
(that are not present in JavaScript) to JavaScript
• Starts with JavaScript, ends with JavaScript. TypeScipt is JavaScript. Any
valid .js file can be renamed .ts and compiled with other TypeScript files.
• Runs on Any browser, Any host, Any OS.
• Open Source
– The compiler is an open source project and released under the Apache 2.0
license.
• TypeScript purposefully borrows ideas from EcmaScript 6 (ES6 Harmony)
spec – class, module
Bit of History
• Typescript was first made public in October 2012 (at version 0.8), after
two years of internal development at Microsoft.
• TypeScript 0.9, released in 2013, added support for generics
• TypeScript 1.0 was released at Build 2014. Visual Studio 2013 Update 2
provides built-in support for TypeScript.
• In July 2014, the development team announced a new TypeScript
compiler, claiming 5x performance gains.
– Source code, which was initially hosted on Codeplex, was moved to GitHub
Features
• Optional Static Type Annotation / Static Typing
• Additional Features for Functions
– Types for function parameters and return type, optional and default parameter, rest
parameter, overloading
• Class
– Field, Property, Method, Constructor, Event, Static methods, Inheritance
• Interface
• Module
• Generics
• Declaration Merging
• Few other features (Enum) …
• TypeScript comes with
– TypeScript Compiler (tsc)
– TypeScript Language Service (TLS) / Visual Studio extension
– Playground (http://www.typescriptlang.org/)
– Declaration files (*.d.ts) for DOM, jQuery, node.js …
– Language Spec (1.0) and code examples
Types / Optional Type
Annotation
Optional Type Annotation
• TypeScript allows annotating variables with types
• Purely a design time feature. No additional code is emitted in the final
JavaScript that TypeScript compiler produces.
• If there’s a type mismatch TypeScript shows a warning.
Types / Optional Type Annotation
• Optional Static Types
– Any
– Primitive
• Number
• Boolean
• String
• Void
• Null
• Undefined -> same as JavaScript “undefined” type
– Array
– Enum
Datatypes
• Does not have separate integer and float/double type
• All numbers in TypeScript are floating point values. These floating
point numbers get the type 'number'.
var x:number = 55
var y:number = 123.4567
• boolean – true/false value
var hasPassport:boolean = true // or false
• string - Both single quote or double quote could be used
var msg1 = 'hello from TypeScript'
var msg2 = "hello from TypeScript"
• No separate char type
var character = 'a'
Optional Type Annotation
• TypeScript tries to infer type
Type Inference
• TypeScript tries to infer type
• Four ways of variable declaration -
1. Declare its type and value (as a literal) in one statement.
2. Declare its type but no value. The value will be set to undefined.
3. Declare its value but no type. The variable will be of type Any (that is, an old-school
dynamic JavaScript variable), but its type may be inferred based on its value.
4. Declare neither value nor type. The variable will be of type Any, and its value will be
undefined.
Array
var cities:string[] = ["Berlin","Bangalore","New York"]
var primes:number[] = [1,3,5,7,11,13]
var bools:boolean[] = [true,false,false,true]
Enum
• Addition to JavaScript datatypes. Similar to C# enum
• Like languages like C#, an enum is a way of giving more friendly
names to sets of numeric values.
• By default, enums begin numbering their members starting at 0. You
can change this by manually setting the value of one its members.
Any
• Useful to describe the type of variables that we may not know when
we are writing the application.
• May come from dynamic content, eg from the user or 3rd party
library.
• Allows to opt-out of type-checking and let the values pass through
compile-time checks.
• Same as not declaring any datatype – uses JavaScript’s dynamic nature
var notSure: any
var list:any[] = [1, true, "free"]
list[1] = 100
Void
• Perhaps the opposite in some ways to 'any' is 'void',
• the absence of having any type at all.
• Commonly used as the return type of functions that do not return a
value
function warnUser(): void {
alert("This is my warning message");
}
Function
Function Overview
• Functions are the fundamental building block of any applications in
JavaScript.
• JavaScript is a functional programming language, and so supports first
class functions.
• Allows build up layers of abstraction, mimicking classes, information
hiding, and modules (JavaScript does not support class, module,
private members).
• In TypeScript, while there are classes and modules, function still play
the key role in describing how to 'do' things.
• TypeScript adds some new capabilities to the standard JavaScript
functions to make them easier to work with.
– Type Annotation for parameter and return type
– Optional and Default Parameter
– Rest Parameter
– Function Overloads
Function
• Allows parameter and return type annotation
Function (2)
• Shows warning for type mismatch
Function Overloads
• Allows function overloads
Function Overloads (2)
Optional & Default Parameter
• Optional Parameters should have default value that would be used if
the value is not specified while invoking the function
• Should be the last arguments in a function
Optional Parameter Implementation
• Optional Parameters should have the default value that would be used
if the value is not specified while calling the function
Rest Parameter
• Declared as … paramName:[paramType]
Class
Class
• Properties and fields to store data
• Methods to define behavior
• Events to provide interactions between different objects and classes
Field and Property
Method and Constructor
Constructor
• Uses constructor keyword
• public by default, can not be private
Constructor shortcut
Events
Access Modifiers
• public (default) - member is available to all code in another module.
• private - member is available only to other code in the same assembly.
Static Methods
• TypeScript supports static members (methods)
• static methods are visible on the class itself rather than on the instances
Class
JavaScript Constructor Pattern
JavaScript Constructor Pattern (2)
Class – TypeScript uses same
Constructor Pattern
Inheritance
• TypeScript supports inheritance of class through extends keyword
Module
Module
• Modules can be defines using module keyword
• A module can contain sub module, class, interface or enum. Can not
directly contain functions (similar to C#, Java)
• Modules can be nested (sub module)
• Class, Interfaces can be exposed using export keyword
Interface
Interface
• Declared using interface keyword
• Like many other TypeScript feature it’s purely a Design time feature.
No additional code is emitted for this!
• TS compiler shows error when Interface signature and implementation
does not match
Interface (Cont’d)
Optional Property
• Optional properties can be declared for an interface (using ?)
• Optional properties need not be implemented
Interface
Mixin
Mixin
• Along with traditional OO hierarchies, another popular way of building
up classes from reusable components is to build them by combining
simpler partial classes – called Mixin
• Several languages support Mixin (e.g. Trait in PHP and Scala).
• This pattern in popular in JavaScript community, so TypeScript
provides language support.
In object-oriented programming languages, a mixin is a class
which contains a combination of methods from other classes.
Mixin - Wikipedia, the free encyclopedia
Mixins Person
Employee
ManagerProgrammer
Mixins (Cont’d)
Mixins (Cont’d)
JavaScript gochas (not fixed in TS)
• TypeScript does not introduce block scope (JavaScript only supports
function scope)
• ; is still optional in TypeScript also (; is not mandatory in JavaScript and
it tries to infer ; and sometime does it differently than expected)
• == vs === (and != vs !==)
== checks for value equality only
=== checks for both type and value equality
• global variables (variables declared outside of function), implied global
(variables declared within function without var keyword)
• issues with floating point (.1 + .2 != .3, it’s something like .3000…00004)

More Related Content

What's hot (20)

PPTX
Introducing type script
Remo Jansen
 
PPTX
Typescript in 30mins
Udaya Kumar
 
PDF
TypeScript Introduction
Dmitry Sheiko
 
PDF
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
PPT
TypeScript Presentation
Patrick John Pacaña
 
PPTX
TypeScript intro
Ats Uiboupin
 
PPTX
Angular modules in depth
Christoffer Noring
 
PPTX
TypeScript
Udaiappa Ramachandran
 
PPTX
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
PDF
TypeScript Best Practices
felixbillon
 
PPTX
Type script - advanced usage and practices
Iwan van der Kleijn
 
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
PPTX
Why TypeScript?
FITC
 
PDF
Asynchronous JavaScript Programming
Haim Michael
 
PPTX
React hooks
Ramy ElBasyouni
 
PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PPTX
TypeScript: Basic Features and Compilation Guide
Nascenia IT
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPT
Introduction to Javascript
Amit Tyagi
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
Introducing type script
Remo Jansen
 
Typescript in 30mins
Udaya Kumar
 
TypeScript Introduction
Dmitry Sheiko
 
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
TypeScript Presentation
Patrick John Pacaña
 
TypeScript intro
Ats Uiboupin
 
Angular modules in depth
Christoffer Noring
 
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
TypeScript Best Practices
felixbillon
 
Type script - advanced usage and practices
Iwan van der Kleijn
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
Why TypeScript?
FITC
 
Asynchronous JavaScript Programming
Haim Michael
 
React hooks
Ramy ElBasyouni
 
JavaScript & Dom Manipulation
Mohammed Arif
 
TypeScript: Basic Features and Compilation Guide
Nascenia IT
 
Introduction to JavaScript
Andres Baravalle
 
Introduction to Javascript
Amit Tyagi
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 

Viewers also liked (16)

PDF
Angular 2 - Typescript
Nathan Krasney
 
PDF
TypeScript Seminar
Haim Michael
 
PDF
Power Leveling your TypeScript
Offirmo
 
PPTX
Typescript tips & tricks
Ori Calvo
 
PDF
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
Micael Gallego
 
PPTX
TypeScript
GetDev.NET
 
PDF
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
Ontico
 
PDF
Typescript + Graphql = <3
felixbillon
 
PPTX
TypeScript - Silver Bullet for the Full-stack Developers
Rutenis Turcinas
 
PPTX
002. Introducere in type script
Dmitrii Stoian
 
PDF
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
PPTX
Typescript
Nikhil Thomas
 
PDF
Александр Русаков - TypeScript 2 in action
MoscowJS
 
PDF
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
MoscowJS
 
PDF
TypeScript for Java Developers
Yakov Fain
 
PDF
TypeScriptで快適javascript
AfiruPain NaokiSoga
 
Angular 2 - Typescript
Nathan Krasney
 
TypeScript Seminar
Haim Michael
 
Power Leveling your TypeScript
Offirmo
 
Typescript tips & tricks
Ori Calvo
 
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
Micael Gallego
 
TypeScript
GetDev.NET
 
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
Ontico
 
Typescript + Graphql = <3
felixbillon
 
TypeScript - Silver Bullet for the Full-stack Developers
Rutenis Turcinas
 
002. Introducere in type script
Dmitrii Stoian
 
TypeScript: Angular's Secret Weapon
Laurent Duveau
 
Typescript
Nikhil Thomas
 
Александр Русаков - TypeScript 2 in action
MoscowJS
 
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
MoscowJS
 
TypeScript for Java Developers
Yakov Fain
 
TypeScriptで快適javascript
AfiruPain NaokiSoga
 
Ad

Similar to TypeScript Overview (20)

PPTX
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
PPTX
Typescript: Beginner to Advanced
Talentica Software
 
PDF
TypeScript Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
typescript.pptx
ZeynepOtu
 
PDF
TYPESCRIPT.pdfgshshhsjajajsjsjjsjajajjajjj
sonidsxyz02
 
DOC
Typescript Basics
Manikandan [M M K]
 
PPTX
Typescript language extension of java script
michaelaaron25322
 
PDF
TypeScipt - Get Started
Krishnanand Sivaraj
 
PPTX
Type script
Zunair Shoes
 
PDF
Reasons to Use Typescript for Your Next Project Over Javascript.pdf
MobMaxime
 
PDF
Introduction to TypeScript by Winston Levi
Winston Levi
 
PPTX
Rits Brown Bag - TypeScript
Right IT Services
 
PDF
Back to the Future with TypeScript
Aleš Najmann
 
PPTX
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
PPTX
11_typescript.pptx for north south university course cse425
AnikSahaToni19126196
 
PPTX
TypeScript . the JavaScript developer best friend!
Alessandro Giorgetti
 
PPTX
Type script
Mallikarjuna G D
 
PPTX
TypeScript 101
rachelterman
 
PPTX
Why do we need TypeScript?
Nitay Neeman
 
PPTX
The advantage of developing with TypeScript
Corley S.r.l.
 
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
Typescript: Beginner to Advanced
Talentica Software
 
TypeScript Interview Questions PDF By ScholarHat
Scholarhat
 
typescript.pptx
ZeynepOtu
 
TYPESCRIPT.pdfgshshhsjajajsjsjjsjajajjajjj
sonidsxyz02
 
Typescript Basics
Manikandan [M M K]
 
Typescript language extension of java script
michaelaaron25322
 
TypeScipt - Get Started
Krishnanand Sivaraj
 
Type script
Zunair Shoes
 
Reasons to Use Typescript for Your Next Project Over Javascript.pdf
MobMaxime
 
Introduction to TypeScript by Winston Levi
Winston Levi
 
Rits Brown Bag - TypeScript
Right IT Services
 
Back to the Future with TypeScript
Aleš Najmann
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
11_typescript.pptx for north south university course cse425
AnikSahaToni19126196
 
TypeScript . the JavaScript developer best friend!
Alessandro Giorgetti
 
Type script
Mallikarjuna G D
 
TypeScript 101
rachelterman
 
Why do we need TypeScript?
Nitay Neeman
 
The advantage of developing with TypeScript
Corley S.r.l.
 
Ad

More from Aniruddha Chakrabarti (20)

PDF
Pinecone Vector Database.pdf
Aniruddha Chakrabarti
 
PDF
Mphasis-Annual-Report-2018.pdf
Aniruddha Chakrabarti
 
PDF
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Aniruddha Chakrabarti
 
PDF
NLP using JavaScript Natural Library
Aniruddha Chakrabarti
 
PPTX
Dart programming language
Aniruddha Chakrabarti
 
PPTX
Third era of computing
Aniruddha Chakrabarti
 
PPTX
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
PPTX
Amazon alexa - building custom skills
Aniruddha Chakrabarti
 
PDF
Using Node-RED for building IoT workflows
Aniruddha Chakrabarti
 
PDF
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Aniruddha Chakrabarti
 
PDF
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
PDF
Future of .NET - .NET on Non Windows Platforms
Aniruddha Chakrabarti
 
PPTX
CoAP - Web Protocol for IoT
Aniruddha Chakrabarti
 
PPTX
Groovy Programming Language
Aniruddha Chakrabarti
 
PDF
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Aniruddha Chakrabarti
 
PPTX
Level DB - Quick Cheat Sheet
Aniruddha Chakrabarti
 
PPTX
Overview of CoffeeScript
Aniruddha Chakrabarti
 
PPTX
memcached Distributed Cache
Aniruddha Chakrabarti
 
PPTX
Redis and it's data types
Aniruddha Chakrabarti
 
Pinecone Vector Database.pdf
Aniruddha Chakrabarti
 
Mphasis-Annual-Report-2018.pdf
Aniruddha Chakrabarti
 
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Aniruddha Chakrabarti
 
NLP using JavaScript Natural Library
Aniruddha Chakrabarti
 
Dart programming language
Aniruddha Chakrabarti
 
Third era of computing
Aniruddha Chakrabarti
 
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
Amazon alexa - building custom skills
Aniruddha Chakrabarti
 
Using Node-RED for building IoT workflows
Aniruddha Chakrabarti
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Aniruddha Chakrabarti
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
Future of .NET - .NET on Non Windows Platforms
Aniruddha Chakrabarti
 
CoAP - Web Protocol for IoT
Aniruddha Chakrabarti
 
Groovy Programming Language
Aniruddha Chakrabarti
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Aniruddha Chakrabarti
 
Level DB - Quick Cheat Sheet
Aniruddha Chakrabarti
 
Overview of CoffeeScript
Aniruddha Chakrabarti
 
memcached Distributed Cache
Aniruddha Chakrabarti
 
Redis and it's data types
Aniruddha Chakrabarti
 

Recently uploaded (20)

PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Human Resources Information System (HRIS)
Amity University, Patna
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Import Data Form Excel to Tally Services
Tally xperts
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 

TypeScript Overview

  • 1. Aniruddha Chakrabarti Sr. Principal Architect & Sr. Manager, Accenture [email protected] | in.linkedin.com/in/aniruddhac
  • 2. Context • Writing large applications in JavaScript is difficult, not originally designed for large complex applications (mostly a scripting language, with functional programming constructs) • Lacks structuring mechanisms like Class, Module, Interface TypeScript is a language for application scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plan JavaScript. TypeScript adds Static Typing and structuring (class, module) to JavaScript.
  • 3. Fix/Improve JavaScript – different approaches 1. Through Library and Frameworks – jQuery, AngularJS, Knockout, Ext JS, Bootstrap …. (new libraries are being created and getting popular everyday) 2. New language that extend/improve language features of JavaScript. Superset of JavaScript. Compiles to JavaScript – CoffeeScript, TypeScript 3. Entirely new language with many new features that compile to JavaScript – GWT (Google Web Toolkit), Dart https://github.com/jashkenas/coffeescript/wiki/list-of-languages-that-compile-to-js
  • 4. What is TypeScript • Helps in large scale JavaScript application development. • Adds additional features like Static Type (optional), Class, Module etc (that are not present in JavaScript) to JavaScript • Starts with JavaScript, ends with JavaScript. TypeScipt is JavaScript. Any valid .js file can be renamed .ts and compiled with other TypeScript files. • Runs on Any browser, Any host, Any OS. • Open Source – The compiler is an open source project and released under the Apache 2.0 license. • TypeScript purposefully borrows ideas from EcmaScript 6 (ES6 Harmony) spec – class, module
  • 5. Bit of History • Typescript was first made public in October 2012 (at version 0.8), after two years of internal development at Microsoft. • TypeScript 0.9, released in 2013, added support for generics • TypeScript 1.0 was released at Build 2014. Visual Studio 2013 Update 2 provides built-in support for TypeScript. • In July 2014, the development team announced a new TypeScript compiler, claiming 5x performance gains. – Source code, which was initially hosted on Codeplex, was moved to GitHub
  • 6. Features • Optional Static Type Annotation / Static Typing • Additional Features for Functions – Types for function parameters and return type, optional and default parameter, rest parameter, overloading • Class – Field, Property, Method, Constructor, Event, Static methods, Inheritance • Interface • Module • Generics • Declaration Merging • Few other features (Enum) … • TypeScript comes with – TypeScript Compiler (tsc) – TypeScript Language Service (TLS) / Visual Studio extension – Playground (http://www.typescriptlang.org/) – Declaration files (*.d.ts) for DOM, jQuery, node.js … – Language Spec (1.0) and code examples
  • 7. Types / Optional Type Annotation
  • 8. Optional Type Annotation • TypeScript allows annotating variables with types • Purely a design time feature. No additional code is emitted in the final JavaScript that TypeScript compiler produces. • If there’s a type mismatch TypeScript shows a warning.
  • 9. Types / Optional Type Annotation • Optional Static Types – Any – Primitive • Number • Boolean • String • Void • Null • Undefined -> same as JavaScript “undefined” type – Array – Enum
  • 10. Datatypes • Does not have separate integer and float/double type • All numbers in TypeScript are floating point values. These floating point numbers get the type 'number'. var x:number = 55 var y:number = 123.4567 • boolean – true/false value var hasPassport:boolean = true // or false • string - Both single quote or double quote could be used var msg1 = 'hello from TypeScript' var msg2 = "hello from TypeScript" • No separate char type var character = 'a'
  • 11. Optional Type Annotation • TypeScript tries to infer type
  • 12. Type Inference • TypeScript tries to infer type • Four ways of variable declaration - 1. Declare its type and value (as a literal) in one statement. 2. Declare its type but no value. The value will be set to undefined. 3. Declare its value but no type. The variable will be of type Any (that is, an old-school dynamic JavaScript variable), but its type may be inferred based on its value. 4. Declare neither value nor type. The variable will be of type Any, and its value will be undefined.
  • 13. Array var cities:string[] = ["Berlin","Bangalore","New York"] var primes:number[] = [1,3,5,7,11,13] var bools:boolean[] = [true,false,false,true]
  • 14. Enum • Addition to JavaScript datatypes. Similar to C# enum • Like languages like C#, an enum is a way of giving more friendly names to sets of numeric values. • By default, enums begin numbering their members starting at 0. You can change this by manually setting the value of one its members.
  • 15. Any • Useful to describe the type of variables that we may not know when we are writing the application. • May come from dynamic content, eg from the user or 3rd party library. • Allows to opt-out of type-checking and let the values pass through compile-time checks. • Same as not declaring any datatype – uses JavaScript’s dynamic nature var notSure: any var list:any[] = [1, true, "free"] list[1] = 100
  • 16. Void • Perhaps the opposite in some ways to 'any' is 'void', • the absence of having any type at all. • Commonly used as the return type of functions that do not return a value function warnUser(): void { alert("This is my warning message"); }
  • 18. Function Overview • Functions are the fundamental building block of any applications in JavaScript. • JavaScript is a functional programming language, and so supports first class functions. • Allows build up layers of abstraction, mimicking classes, information hiding, and modules (JavaScript does not support class, module, private members). • In TypeScript, while there are classes and modules, function still play the key role in describing how to 'do' things. • TypeScript adds some new capabilities to the standard JavaScript functions to make them easier to work with. – Type Annotation for parameter and return type – Optional and Default Parameter – Rest Parameter – Function Overloads
  • 19. Function • Allows parameter and return type annotation
  • 20. Function (2) • Shows warning for type mismatch
  • 21. Function Overloads • Allows function overloads
  • 23. Optional & Default Parameter • Optional Parameters should have default value that would be used if the value is not specified while invoking the function • Should be the last arguments in a function
  • 24. Optional Parameter Implementation • Optional Parameters should have the default value that would be used if the value is not specified while calling the function
  • 25. Rest Parameter • Declared as … paramName:[paramType]
  • 26. Class
  • 27. Class • Properties and fields to store data • Methods to define behavior • Events to provide interactions between different objects and classes
  • 30. Constructor • Uses constructor keyword • public by default, can not be private
  • 33. Access Modifiers • public (default) - member is available to all code in another module. • private - member is available only to other code in the same assembly.
  • 34. Static Methods • TypeScript supports static members (methods) • static methods are visible on the class itself rather than on the instances
  • 35. Class
  • 38. Class – TypeScript uses same Constructor Pattern
  • 39. Inheritance • TypeScript supports inheritance of class through extends keyword
  • 41. Module • Modules can be defines using module keyword • A module can contain sub module, class, interface or enum. Can not directly contain functions (similar to C#, Java) • Modules can be nested (sub module) • Class, Interfaces can be exposed using export keyword
  • 43. Interface • Declared using interface keyword • Like many other TypeScript feature it’s purely a Design time feature. No additional code is emitted for this! • TS compiler shows error when Interface signature and implementation does not match
  • 45. Optional Property • Optional properties can be declared for an interface (using ?) • Optional properties need not be implemented
  • 47. Mixin
  • 48. Mixin • Along with traditional OO hierarchies, another popular way of building up classes from reusable components is to build them by combining simpler partial classes – called Mixin • Several languages support Mixin (e.g. Trait in PHP and Scala). • This pattern in popular in JavaScript community, so TypeScript provides language support. In object-oriented programming languages, a mixin is a class which contains a combination of methods from other classes. Mixin - Wikipedia, the free encyclopedia
  • 52. JavaScript gochas (not fixed in TS) • TypeScript does not introduce block scope (JavaScript only supports function scope) • ; is still optional in TypeScript also (; is not mandatory in JavaScript and it tries to infer ; and sometime does it differently than expected) • == vs === (and != vs !==) == checks for value equality only === checks for both type and value equality • global variables (variables declared outside of function), implied global (variables declared within function without var keyword) • issues with floating point (.1 + .2 != .3, it’s something like .3000…00004)