SlideShare a Scribd company logo
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

What's hot

Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
Sunny Sharma
 
TypeScript
TypeScriptTypeScript
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
akhilsreyas
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
Noam Kfir
 
Typescript
TypescriptTypescript
Typescript
Nikhil Thomas
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston Levi
Winston Levi
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
Ats Uiboupin
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
Remo Jansen
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
Andrei Sebastian Cîmpean
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
Offirmo
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
Udaya Kumar
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
Rutenis Turcinas
 
All You Need to Know About Type Script
All You Need to Know About Type ScriptAll You Need to Know About Type Script
All You Need to Know About Type Script
Folio3 Software
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
Alexandre Marreiros
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introduction
Bob German
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
Alessandro Giorgetti
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
Patrick John Pacaña
 
Typescript Basics
Typescript BasicsTypescript Basics
Typescript Basics
Manikandan [M M K]
 

What's hot (20)

Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
 
Typescript
TypescriptTypescript
Typescript
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston Levi
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
All You Need to Know About Type Script
All You Need to Know About Type ScriptAll You Need to Know About Type Script
All You Need to Know About Type Script
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introduction
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
Typescript Basics
Typescript BasicsTypescript Basics
Typescript Basics
 

Similar to TypeScript introduction to scalable javascript application

typescript.pptx
typescript.pptxtypescript.pptx
typescript.pptx
ZeynepOtu
 
Benefits of Typescript.pptx
Benefits of Typescript.pptxBenefits of Typescript.pptx
Benefits of Typescript.pptx
AmitGupta440280
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
Knoldus Inc.
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Thanh Tai
 
Type script is awesome
Type script is awesomeType script is awesome
Type script is awesome
KeithMurgic
 
Type script
Type scriptType script
Type script
Zunair Shoes
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
NexThoughts Technologies
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
michaelaaron25322
 
Why Static Type Checking is Better
Why Static Type Checking is BetterWhy Static Type Checking is Better
Why Static Type Checking is Better
Andrew Rota
 
Type script
Type scriptType script
Type script
srinivaskapa1
 
Type Script Conceitos de ts para projetos front-end React - por ruben marcus
Type Script   Conceitos de ts para projetos front-end React - por ruben marcusType Script   Conceitos de ts para projetos front-end React - por ruben marcus
Type Script Conceitos de ts para projetos front-end React - por ruben marcus
Ruben Marcus Luz Paschoarelli
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
Talentica Software
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScript
WrapPixel
 
TypeScript, Dart, CoffeeScript and JavaScript Comparison
TypeScript, Dart, CoffeeScript and JavaScript ComparisonTypeScript, Dart, CoffeeScript and JavaScript Comparison
TypeScript, Dart, CoffeeScript and JavaScript Comparison
Haim Michael
 
Type script
Type scriptType script
Type script
Mallikarjuna G D
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
Yakov Fain
 
Nodejs & Typescript
Nodejs & TypescriptNodejs & Typescript
Nodejs & Typescript
Knoldus Inc.
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
Laurent Duveau
 

Similar to TypeScript introduction to scalable javascript application (20)

typescript.pptx
typescript.pptxtypescript.pptx
typescript.pptx
 
Benefits of Typescript.pptx
Benefits of Typescript.pptxBenefits of Typescript.pptx
Benefits of Typescript.pptx
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Type script is awesome
Type script is awesomeType script is awesome
Type script is awesome
 
Type script
Type scriptType script
Type script
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
Why Static Type Checking is Better
Why Static Type Checking is BetterWhy Static Type Checking is Better
Why Static Type Checking is Better
 
Type script
Type scriptType script
Type script
 
Type Script Conceitos de ts para projetos front-end React - por ruben marcus
Type Script   Conceitos de ts para projetos front-end React - por ruben marcusType Script   Conceitos de ts para projetos front-end React - por ruben marcus
Type Script Conceitos de ts para projetos front-end React - por ruben marcus
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScript
 
TypeScript, Dart, CoffeeScript and JavaScript Comparison
TypeScript, Dart, CoffeeScript and JavaScript ComparisonTypeScript, Dart, CoffeeScript and JavaScript Comparison
TypeScript, Dart, CoffeeScript and JavaScript Comparison
 
Type script
Type scriptType script
Type script
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Nodejs & Typescript
Nodejs & TypescriptNodejs & Typescript
Nodejs & Typescript
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

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