TypeScript
Andrea Paciolla / @PaciollaAndrea
Andrea Paciolla / @PaciollaAndrea
Get in touch with me:
https://github.com/AndreaPaciolla
https://twitter.com/PaciollaAndrea
http://andreapaciolla.it
Frontend Engineer at ObjectWay
Agenda
1. Introduction
2. TypeScript, why?
3. Installation
4. Features
5. TypeScript Alternatives
6. Where TypeScript is used?
7. Conclusion
1. Introduction
TypeScript is...
TypeScript lets you write JavaScript the way
you really want to.
TypeScript is a typed superset of JavaScript
that compiles to plain JavaScript.
Any browser. Any host. Any OS. Open Source.
It follows the ECMAScript standards in any new versions
Overview
▷ Syntax based on ECMAScript 4 & ECMASCript 6 proposals
▷ TS is first and foremost a superset of JS
▷ Any regular Javascript is valid TypeScript Code
Well...
2. TypeScript,
why?
Main reasons to choose TypeScript are...
1. Compile time
2. Strong typing
3. Type definitions
4. Encapsulation
5. Private and public accessors
Compile time
JavaScript is an interpreted language errors are revealed at run time
TypeScript compiles your code errors are revealed at compile time
Strong Typing
Object oriented languages do not allow the type of a
variable to change – hence they are called strongly typed
languages.
The IDE can understand what type of variable you are
working with, and can bring better autocomplete or
Intellisense options
Type Definitions
- TypeScript uses files with a .d.ts extension as a sort of "header" file
- GitHub repository hosts definition files: DefinitelyTyped
Encapsulation
Through classes, is accomplished by either using the prototype pattern, or by
using the closure pattern.
Private and public accessors
A compile-time feature only Private variables are hidden outside of a class
JavaScript does not have private vars.
3. Installation
Get TypeScript setup
For more details check: https://www.typescriptlang.org/docs/tutorial.html
Via npm
$ npm install -g typescript
Visual Studio has a plugin
WebStorm has got built-in plugin
4. Features
TypeScript Features
● Data Types Supported
● Optional Static Type Annotation
● Classes
● Interface
● Namespace
● Arrow Expressions
● Type Assertions
● Ambient Declarations
● Source File Dependencies
Data Types
● Any (Just when we cannot get the right interface)
● Primitive (most of cases)
○ number
○ boolean
○ string
○ void
○ null
● Array (most of cases)
● Custom (we can define types by using interfaces)
Type Annotation
var a = 987;
a.trim();
// javascript error: typeError: a.trim is not a function on line xxx
var a = 987;
a.trim();
// Property 'trim' does not exist on type 'number'
var a:string = 123;
a.trim()
// cannot convert 'number' to 'string'
TypeScript Classes
● Can implement interfaces
● Inheritance
● Instance methods/members
● Static methods/members
● Single constructor
● Default/Optional parameter
● ES6 class syntax
TypeScript Classes
interface IComplexType {
name: string;
print(): string;
};
class ComplexType implements IComplexType {
name: string;
print(): string {
return "name:" + this.name;
}
};
var complexType: ComplexType = new ComplexType();
complexType.name = "complexType";
console.log(complexType.print()); // name:complexType
TypeScript Interfaces
● By convention they start with ‘I’ - e.g. IWebRTCPeer
● Used in classes with ‘implements’ keyword
● Used on typings context with semicolon syntax - e.g. let dot: IDot;
TypeScript Namespaces
// Used to group classes and interfaces under a common name
declare namespace WebRTCTypings {
interface IComplexType {
name: string;
print(): string;
};
}
var complexType: WebRTCTypings.ComplexType;
TypeScript Arrow Expressions
● Implicit return
● No braces for single expression
● Part of ES6
● Lexically scoped this
● You don't need to keep typing function
● It lexically captures the meaning of arguments
TypeScript Arrow Expressions Example
function(arg) {
return arg.toUpperCase;
}
// Arrow expression by using the fat arrow operator
(arg) => arg.toUpperCase();
TypeScript Type Assertions
TypeScript's type assertion are purely you telling the compiler that you know
about the types better than it does, and that it should not second guess you.
TypeScript Type Assertions Example
var foo = {};
foo.bar = 123; // error in js --> bar does not exist
// TS Way
interface IFoo {
bar: number;
}
var foo: IFoo;
foo.bar = 123;
TypeScript Ambient Declarations
A major design goal of TypeScript is to make easy the use of already existing
JavaScript libraries by using declarations.
TypeScript Source File
Get dependencies by using reference.
● Can be done using reference keyword
● Must be the first statement of file
● Paths are relative to the current file
● Can also be done using tsconfig file
5. TypeScript
Alternatives
TypeScript Alternatives?
TypeScript VS Dart / CoffeeScript
6. Where
TypeScript is
used?
Spread TS Worldwide
Typescript is being adopted by tons of
companies each day.
In particular, the Angular 2 adoption of TS is
spreading it more and more.
7. Conclusion
7. Conclusion
PROs
● Highly scalable
● Good for enterprise projects
● Solid abstraction of Ecma Standards
CONs
● Slow compiler
● Not enough d.ts (JS libraries are getting more and more)
● Not for libraries
Bonus
1. TSD vs Typings
2. Reference VS amd-dependency
3. Union Types
4. Function Overloads
5. Namespace instead of modules
That’s all! Thank you
Questions?
Get in touch with me:
https://github.com/AndreaPaciolla
https://twitter.com/PaciollaAndrea
http://andreapaciolla.it

More Related Content

PPTX
TypeScript: Basic Features and Compilation Guide
PDF
Typescript: enjoying large scale browser development
PPTX
Introduction about type script
PPTX
Type script - advanced usage and practices
PDF
TypeScript: coding JavaScript without the pain
PDF
TypeScript Best Practices
PDF
Getting Started with TypeScript
PPTX
Getting started with typescript
TypeScript: Basic Features and Compilation Guide
Typescript: enjoying large scale browser development
Introduction about type script
Type script - advanced usage and practices
TypeScript: coding JavaScript without the pain
TypeScript Best Practices
Getting Started with TypeScript
Getting started with typescript

What's hot (20)

PPTX
Typescript Fundamentals
PPTX
PPTX
Typescript ppt
PPTX
TypeScript Modules
PPTX
Typescript
PDF
Introduction to TypeScript by Winston Levi
PPTX
TypeScript intro
PDF
TypeScript - An Introduction
PPTX
Introducing type script
PDF
Typescript for the programmers who like javascript
PDF
Power Leveling your TypeScript
PPTX
Typescript in 30mins
PPTX
TypeScript - Silver Bullet for the Full-stack Developers
PPTX
All You Need to Know About Type Script
PPT
Learning typescript
PPTX
Typescript 101 introduction
PPTX
AngularConf2015
PPT
TypeScript Presentation
DOC
Typescript Basics
Typescript Fundamentals
Typescript ppt
TypeScript Modules
Typescript
Introduction to TypeScript by Winston Levi
TypeScript intro
TypeScript - An Introduction
Introducing type script
Typescript for the programmers who like javascript
Power Leveling your TypeScript
Typescript in 30mins
TypeScript - Silver Bullet for the Full-stack Developers
All You Need to Know About Type Script
Learning typescript
Typescript 101 introduction
AngularConf2015
TypeScript Presentation
Typescript Basics
Ad

Similar to TypeScript introduction to scalable javascript application (20)

PDF
Introduction to TypeScript
PDF
Reasons to Use Typescript for Your Next Project Over Javascript.pdf
PDF
TypeScipt - Get Started
PDF
An Introduction to TypeScript
PPTX
typescript.pptx
PPTX
Rits Brown Bag - TypeScript
PDF
TYPESCRIPT.pdfgshshhsjajajsjsjjsjajajjajjj
PPTX
Complete Notes on Angular 2 and TypeScript
PPTX
Type script
PDF
TypeScript Interview Questions PDF By ScholarHat
PPTX
TypeScript Introduction
PPTX
TypeScript 101
PDF
Angular - Chapter 2 - TypeScript Programming
PPTX
Benefits of Typescript.pptx
PPTX
Typescript: Beginner to Advanced
PPTX
Typescript: JS code just got better!
PPTX
Typescript language extension of java script
PDF
Using type script to build better apps
PDF
Using type script to build better apps
PPTX
TypeScript Overview
Introduction to TypeScript
Reasons to Use Typescript for Your Next Project Over Javascript.pdf
TypeScipt - Get Started
An Introduction to TypeScript
typescript.pptx
Rits Brown Bag - TypeScript
TYPESCRIPT.pdfgshshhsjajajsjsjjsjajajjajjj
Complete Notes on Angular 2 and TypeScript
Type script
TypeScript Interview Questions PDF By ScholarHat
TypeScript Introduction
TypeScript 101
Angular - Chapter 2 - TypeScript Programming
Benefits of Typescript.pptx
Typescript: Beginner to Advanced
Typescript: JS code just got better!
Typescript language extension of java script
Using type script to build better apps
Using type script to build better apps
TypeScript Overview
Ad

Recently uploaded (20)

PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPTX
Configure Apache Mutual Authentication
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Comparative analysis of machine learning models for fake news detection in so...
sbt 2.0: go big (Scala Days 2025 edition)
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Rapid Prototyping: A lecture on prototyping techniques for interface design
NewMind AI Weekly Chronicles – August ’25 Week IV
Module 1 Introduction to Web Programming .pptx
Early detection and classification of bone marrow changes in lumbar vertebrae...
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Configure Apache Mutual Authentication
Advancing precision in air quality forecasting through machine learning integ...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
4 layer Arch & Reference Arch of IoT.pdf
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Comparative analysis of machine learning models for fake news detection in so...

TypeScript introduction to scalable javascript application

  • 2. Andrea Paciolla / @PaciollaAndrea Get in touch with me: https://github.com/AndreaPaciolla https://twitter.com/PaciollaAndrea http://andreapaciolla.it Frontend Engineer at ObjectWay
  • 3. Agenda 1. Introduction 2. TypeScript, why? 3. Installation 4. Features 5. TypeScript Alternatives 6. Where TypeScript is used? 7. Conclusion
  • 5. TypeScript is... TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source. It follows the ECMAScript standards in any new versions
  • 6. Overview ▷ Syntax based on ECMAScript 4 & ECMASCript 6 proposals ▷ TS is first and foremost a superset of JS ▷ Any regular Javascript is valid TypeScript Code
  • 9. Main reasons to choose TypeScript are... 1. Compile time 2. Strong typing 3. Type definitions 4. Encapsulation 5. Private and public accessors
  • 10. Compile time JavaScript is an interpreted language errors are revealed at run time TypeScript compiles your code errors are revealed at compile time
  • 11. Strong Typing Object oriented languages do not allow the type of a variable to change – hence they are called strongly typed languages. The IDE can understand what type of variable you are working with, and can bring better autocomplete or Intellisense options
  • 12. Type Definitions - TypeScript uses files with a .d.ts extension as a sort of "header" file - GitHub repository hosts definition files: DefinitelyTyped
  • 13. Encapsulation Through classes, is accomplished by either using the prototype pattern, or by using the closure pattern.
  • 14. Private and public accessors A compile-time feature only Private variables are hidden outside of a class JavaScript does not have private vars.
  • 16. Get TypeScript setup For more details check: https://www.typescriptlang.org/docs/tutorial.html Via npm $ npm install -g typescript Visual Studio has a plugin WebStorm has got built-in plugin
  • 18. TypeScript Features ● Data Types Supported ● Optional Static Type Annotation ● Classes ● Interface ● Namespace ● Arrow Expressions ● Type Assertions ● Ambient Declarations ● Source File Dependencies
  • 19. Data Types ● Any (Just when we cannot get the right interface) ● Primitive (most of cases) ○ number ○ boolean ○ string ○ void ○ null ● Array (most of cases) ● Custom (we can define types by using interfaces)
  • 20. Type Annotation var a = 987; a.trim(); // javascript error: typeError: a.trim is not a function on line xxx var a = 987; a.trim(); // Property 'trim' does not exist on type 'number' var a:string = 123; a.trim() // cannot convert 'number' to 'string'
  • 21. TypeScript Classes ● Can implement interfaces ● Inheritance ● Instance methods/members ● Static methods/members ● Single constructor ● Default/Optional parameter ● ES6 class syntax
  • 22. TypeScript Classes interface IComplexType { name: string; print(): string; }; class ComplexType implements IComplexType { name: string; print(): string { return "name:" + this.name; } }; var complexType: ComplexType = new ComplexType(); complexType.name = "complexType"; console.log(complexType.print()); // name:complexType
  • 23. TypeScript Interfaces ● By convention they start with ‘I’ - e.g. IWebRTCPeer ● Used in classes with ‘implements’ keyword ● Used on typings context with semicolon syntax - e.g. let dot: IDot;
  • 24. TypeScript Namespaces // Used to group classes and interfaces under a common name declare namespace WebRTCTypings { interface IComplexType { name: string; print(): string; }; } var complexType: WebRTCTypings.ComplexType;
  • 25. TypeScript Arrow Expressions ● Implicit return ● No braces for single expression ● Part of ES6 ● Lexically scoped this ● You don't need to keep typing function ● It lexically captures the meaning of arguments
  • 26. TypeScript Arrow Expressions Example function(arg) { return arg.toUpperCase; } // Arrow expression by using the fat arrow operator (arg) => arg.toUpperCase();
  • 27. TypeScript Type Assertions TypeScript's type assertion are purely you telling the compiler that you know about the types better than it does, and that it should not second guess you.
  • 28. TypeScript Type Assertions Example var foo = {}; foo.bar = 123; // error in js --> bar does not exist // TS Way interface IFoo { bar: number; } var foo: IFoo; foo.bar = 123;
  • 29. TypeScript Ambient Declarations A major design goal of TypeScript is to make easy the use of already existing JavaScript libraries by using declarations.
  • 30. TypeScript Source File Get dependencies by using reference. ● Can be done using reference keyword ● Must be the first statement of file ● Paths are relative to the current file ● Can also be done using tsconfig file
  • 34. Spread TS Worldwide Typescript is being adopted by tons of companies each day. In particular, the Angular 2 adoption of TS is spreading it more and more.
  • 36. 7. Conclusion PROs ● Highly scalable ● Good for enterprise projects ● Solid abstraction of Ecma Standards CONs ● Slow compiler ● Not enough d.ts (JS libraries are getting more and more) ● Not for libraries
  • 37. Bonus 1. TSD vs Typings 2. Reference VS amd-dependency 3. Union Types 4. Function Overloads 5. Namespace instead of modules
  • 38. That’s all! Thank you Questions? Get in touch with me: https://github.com/AndreaPaciolla https://twitter.com/PaciollaAndrea http://andreapaciolla.it