SlideShare ist ein Scribd-Unternehmen logo
1 von 32
webnextconf.eu
TypeScript
The JavaScript developer best friend!
Who Am I ?
Alessandro Giorgetti
co-owner: SID s.r.l.
co-founder: DotNetMarche, DevMarche
Facebook: https://www.facebook.com/giorgetti.alessandro
Twitter: @a_giorgetti
LinkedIn: https://it.linkedin.com/in/giorgettialessandro
E-mail: alessandro.giorgetti@live.com
Blog: www.primordialcode.com
Agenda
• TypeScript why? what?
• Tooling Setup we need a development environment, right !?!
• The Language (features, futures and pitfalls)
• Q. & A.
Code on GitHub
https://github.com/AGiorgetti/
WebNextConf2015
TypeScript
Why? What?
JavaScript 'the good parts'
• It's a real cross platform language!
• It's everywhere (client side and server side).
• It's easy to learn and to start with!
• It's a dynamic language: flexible and powerful.
• You have 'the freedom' to do whatever you want with
any object.
JavaScript 'the not so good parts'
• It does not have a 'true' type system: how do you check the proper parameter are passed to a
function? (test... Test... Test...)
• Global namespace issues.
• Your code can become messy quickly: lack of maintainability, low code reuse and so on...
• Having a 'relaxed' type system leads to confusion: different equality operators: == support
implicit type conversion, === it does not!
• It can be 'troublesome' for devs used to OO paradigms:
• Lack of class based programming techniques.
• 'New / Unusual' design patterns (prototypical inheritance, revealing module patterns etc...).
• You need to define a code style guide.
• You need to enforce that style guide: it needs discipline!
• It's not well suited for very large [enterprise level] projects:
• It lacks maintainability (code analysis, refactoring)
• It lacks in code structuring (module, classes, …)
• Tooling isn’t good enough!
The good news: JavaScript is evolving! ES6* to the rescue!
* the problem is you cannot have full access to those feature right now! You'll have to wait... and ES5 will be out in the wild for quite some time
anyway...
Sometimes…
JavaScript tooling SUX*!
* I apologize for the chatchphrase to all the Developers that
worked hard to give us the best experience they could.
TypeScript - what is it? why use it?
• It's an Open Source project from Microsoft Technologies.
• An attempt to 'fix' the missing parts of JavaScript.
• A Superset of JavaScript => JavaScript + Static Types (and Classes and Modules)
(+ other goodies).
• Compiles to plain JavaScript (target: ES3, ES5, ES6).
• Any valid JavaScript application is also a TypeScript application.
• Gives us a chance to use new features of the language that will be available in
ES6+ (classes, modules, decorators, etc...: better code structuring and object-
oriented programming techniques).
• Enables BETTER development time tool support (intellisense, syntax checking,
code analysis & navigation, refactoring, documentation).
• Can extend the language beyond the standard (decorators, async/await).
• The best part of it: It's all a development time illusion!
Tooling Setup
we need a development environment, right !?!
Setup TypeScript
You have several ways to install TypeScript (globally
and locally):
http://www.typescriptlang.org/#Download
Editor / IDE
Grab a good code editor
(better with TypeScript support, and provide the proper integration with your task runner of choice)
• Visual Studio 2013, 2015+
• Visual Studio Code
• Webstorm
• Atom
• Sublime
• Eclipse
• …
Editor Setup (Visual Studio Code)
TSC - the TypeScript compiler
TSC is a source-to-source compiler (a transpiler).
There are lots of options that allow you to:
- concatenate different files in a single output file.
- generate sourcemaps.
- generate module loading code (node.js or require.js).
You can play with the TypeScript playground or setup
your environment to see it in action.
tsc app.tsapp.ts app.js
TSD - TypeScript Definition Files package manager
TypeScript Definition File (ambient declaration file)
• .d.ts extension.
• Allows the definition of strong types.
• Provide type definition for external JavaScript libraries.
There's a community driven project on GitHub that tracks all
of them:
DefinitelyTyped (http://definitelytyped.org/)
TSD: a specialized package manager to look for definition files
inside DefinitelyTyped repository
(http://definitelytyped.org/tsd/)
Demo
From JavaScript to TypeScript
A quick overview!
Types
number, string, etc... all the standard JavaScript Types
any: I can be any type, disable the type checking!
void: I have no type at all (function return value)!
enum / const enum: define enumerated values.
<T>: casting! This is not a type conversion!
type name = : define an alias for a type name.
generics: great for code reuse! We can specify constraints if we want.
Interfaces
Interfaces are used to define the SHAPE of our objects!
They are used to define Contracts within our code!
TypeScript type checking is based on a concept called
Structural Typing (or Duck Typing), which means the
object shape / structure is the most important thing!
Two different interfaces (objects) that expose the same
properties are considered compatible. This mean you can
assign 'apples' to 'oranges' under specific conditions.
Interfaces
Interfaces can describe:
• Objects
• Functions
• Arrays / Dictionaries
• Hybrid Types ('things' that are both objects and functions)
Interfaces support:
• Inheritance
They do not support accessors (get / set): you need to convert the 'property' to a
'getProperty()' function if you wanna give that readonly behavior
Classes
Classes implement the behaviors of an entity.
They have support for:
• accessors (get, set) [ES5+]
• modifiers: public, private, protected
• constructor
• inheritable
• static properties
• abstract (class & methods)
• interface implementation
Classes also define Types, they have two sides:
• instance side (the properties involved in structural type checking)
• static side (constructor and static properties, not involved in the type checking)
Classes - Pay Attention to...
The 'this': most of the times it represents the instance of the
class itself (like in C#).
The 'this' has a different meaning in function expression and
when using the 'arrow syntax':
• function() { … }: this act exactly as expected in strict
mode (it can be undefined or whatever it was when
entering the function execution context).
• () => { … }: this always refers to the class instance.
Composition / Encapsulation patterns: don't mess up with the
this! Always delegate the function call properly, that is: call
the function on its original object rather than assigning the
pointer to the function to another variable!
Namespace & Module
• Namespaces and Modules are used to add more
structuring to your code.
• Group and Organize objects based on their
behavior or because they are related to each other
in some way (i.e.: all the classes of a specific
feature, a library, etc...).
• Allow to split your code in multiple files.
Namespace
Also called 'internal module':
• export: decide what to expose to the outside world.
• can be split in multiple files.
How to use:
• build the whole application concatenating all the files.
• reference the files using <script> tags in the correct
order.
NO DYNAMIC MODULE LOADING (Node.js / Require.js)
Module
Also called 'external module':
• export: decide what to expose to the outside world.
• have file scope! (map 1:1 with the files that define it).
• any file containing a top-level import or export is considered
a module.
• must use the '--module' compiler switch [commonjs, AMD,
system, ...].
How to use:
• Reference them using the 'import' keyword and assign a
name alias.
• Node.js / Require.js dynamic module loaders.
Decorators (ES7 proposal)
Decorators make it possible to annotate and modify classes and properties at
design time.
A decorator is:
• an expression
• that evaluates to a function
• that takes the target, name, and property descriptor as arguments
• and optionally returns a property descriptor to install on the target object
In TypeScript we have 4 types of decorators:
• ClassDecorator
• MethodDecorator
• PropertyDecorator
• ParameterDecorator
Various / Advanced
TypeScript also has
support for many more
ES6 features:
• Let / const
• Destructuring
declarations
• For..of
• Template strings
• Generators
• Class expressions
And some language
specific / custom
extensions:
• Tuple types
• Union types
• Intersection types
• Decorators (ES7
proposal)
• Async / await
What's Next?
Roadmap:
https://github.com/Microsoft/TypeScript/wiki/Road
map
Thanks All!
I hope you enjoyed the session!
Let’s stay in touch!
Q. & A.
"Speak now or forever hold your peace!"
License
This work is published under:
Creative Commons
Attribution NonCommercial ShareAlike 3.0
License
http://creativecommons.org/licenses/by-nc-sa/3.0/

Weitere ähnliche Inhalte

Was ist angesagt?

Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScriptGil Fink
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponLaurent Duveau
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript FundamentalsSunny Sharma
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviWinston Levi
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersLaurent Duveau
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript ModulesNoam Kfir
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
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 javascriptAndrei Sebastian Cîmpean
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersLaurent Duveau
 
Typescript overview
Typescript overviewTypescript overview
Typescript overviewThanvilahari
 
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 DevelopersRutenis Turcinas
 

Was ist angesagt? (20)

TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston Levi
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
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
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
TypeScript and Angular workshop
TypeScript and Angular workshopTypeScript and Angular workshop
TypeScript and Angular workshop
 
Typescript overview
Typescript overviewTypescript overview
Typescript overview
 
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
 
Typescript
TypescriptTypescript
Typescript
 

Ähnlich wie TypeScript . the JavaScript developer best friend!

The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript Corley S.r.l.
 
TypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptxTypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptxaccordv12
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
 
Getting Started with the TypeScript Language
Getting Started with the TypeScript LanguageGetting Started with the TypeScript Language
Getting Started with the TypeScript LanguageGil Fink
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introductionBirol Efe
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unitKotresh Munavallimatt
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell ModulesJune Blender
 
TypeScript - Javascript done right
TypeScript - Javascript done rightTypeScript - Javascript done right
TypeScript - Javascript done rightWekoslav Stefanovski
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introductionSireesh K
 
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San JoseTypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San JoseSteve Reiner
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type scriptGil Fink
 
TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)Igor Talevski
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3Sisir Ghosh
 
introduction to c #
introduction to c #introduction to c #
introduction to c #Sireesh K
 

Ähnlich wie TypeScript . the JavaScript developer best friend! (20)

The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
 
Angular2
Angular2Angular2
Angular2
 
TypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptxTypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptx
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
Getting Started with the TypeScript Language
Getting Started with the TypeScript LanguageGetting Started with the TypeScript Language
Getting Started with the TypeScript Language
 
Type script
Type scriptType script
Type script
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
TypeScript - Javascript done right
TypeScript - Javascript done rightTypeScript - Javascript done right
TypeScript - Javascript done right
 
Csharp introduction
Csharp introductionCsharp introduction
Csharp introduction
 
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San JoseTypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
iOS Application Exploitation
iOS Application ExploitationiOS Application Exploitation
iOS Application Exploitation
 
java slides
java slidesjava slides
java slides
 
TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 

Mehr von Alessandro Giorgetti

The Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsThe Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsAlessandro Giorgetti
 
AngularConf2016 - A leap of faith !?
AngularConf2016 - A leap of faith !?AngularConf2016 - A leap of faith !?
AngularConf2016 - A leap of faith !?Alessandro Giorgetti
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NETAlessandro Giorgetti
 
DNM19 Sessione1 Orchard Primo Impatto (ita)
DNM19 Sessione1 Orchard Primo Impatto (ita)DNM19 Sessione1 Orchard Primo Impatto (ita)
DNM19 Sessione1 Orchard Primo Impatto (ita)Alessandro Giorgetti
 
DNM19 Sessione2 Orchard Temi e Layout (Ita)
DNM19 Sessione2 Orchard Temi e Layout (Ita)DNM19 Sessione2 Orchard Temi e Layout (Ita)
DNM19 Sessione2 Orchard Temi e Layout (Ita)Alessandro Giorgetti
 

Mehr von Alessandro Giorgetti (8)

Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
Let's talk about... Microservices
Let's talk about... MicroservicesLet's talk about... Microservices
Let's talk about... Microservices
 
The Big Picture - Integrating Buzzwords
The Big Picture - Integrating BuzzwordsThe Big Picture - Integrating Buzzwords
The Big Picture - Integrating Buzzwords
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
AngularConf2016 - A leap of faith !?
AngularConf2016 - A leap of faith !?AngularConf2016 - A leap of faith !?
AngularConf2016 - A leap of faith !?
 
«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
 
DNM19 Sessione1 Orchard Primo Impatto (ita)
DNM19 Sessione1 Orchard Primo Impatto (ita)DNM19 Sessione1 Orchard Primo Impatto (ita)
DNM19 Sessione1 Orchard Primo Impatto (ita)
 
DNM19 Sessione2 Orchard Temi e Layout (Ita)
DNM19 Sessione2 Orchard Temi e Layout (Ita)DNM19 Sessione2 Orchard Temi e Layout (Ita)
DNM19 Sessione2 Orchard Temi e Layout (Ita)
 

Kürzlich hochgeladen

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 

Kürzlich hochgeladen (20)

SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

TypeScript . the JavaScript developer best friend!

  • 3. Who Am I ? Alessandro Giorgetti co-owner: SID s.r.l. co-founder: DotNetMarche, DevMarche Facebook: https://www.facebook.com/giorgetti.alessandro Twitter: @a_giorgetti LinkedIn: https://it.linkedin.com/in/giorgettialessandro E-mail: alessandro.giorgetti@live.com Blog: www.primordialcode.com
  • 4. Agenda • TypeScript why? what? • Tooling Setup we need a development environment, right !?! • The Language (features, futures and pitfalls) • Q. & A.
  • 7. JavaScript 'the good parts' • It's a real cross platform language! • It's everywhere (client side and server side). • It's easy to learn and to start with! • It's a dynamic language: flexible and powerful. • You have 'the freedom' to do whatever you want with any object.
  • 8. JavaScript 'the not so good parts' • It does not have a 'true' type system: how do you check the proper parameter are passed to a function? (test... Test... Test...) • Global namespace issues. • Your code can become messy quickly: lack of maintainability, low code reuse and so on... • Having a 'relaxed' type system leads to confusion: different equality operators: == support implicit type conversion, === it does not! • It can be 'troublesome' for devs used to OO paradigms: • Lack of class based programming techniques. • 'New / Unusual' design patterns (prototypical inheritance, revealing module patterns etc...). • You need to define a code style guide. • You need to enforce that style guide: it needs discipline! • It's not well suited for very large [enterprise level] projects: • It lacks maintainability (code analysis, refactoring) • It lacks in code structuring (module, classes, …) • Tooling isn’t good enough! The good news: JavaScript is evolving! ES6* to the rescue! * the problem is you cannot have full access to those feature right now! You'll have to wait... and ES5 will be out in the wild for quite some time anyway...
  • 9. Sometimes… JavaScript tooling SUX*! * I apologize for the chatchphrase to all the Developers that worked hard to give us the best experience they could.
  • 10. TypeScript - what is it? why use it? • It's an Open Source project from Microsoft Technologies. • An attempt to 'fix' the missing parts of JavaScript. • A Superset of JavaScript => JavaScript + Static Types (and Classes and Modules) (+ other goodies). • Compiles to plain JavaScript (target: ES3, ES5, ES6). • Any valid JavaScript application is also a TypeScript application. • Gives us a chance to use new features of the language that will be available in ES6+ (classes, modules, decorators, etc...: better code structuring and object- oriented programming techniques). • Enables BETTER development time tool support (intellisense, syntax checking, code analysis & navigation, refactoring, documentation). • Can extend the language beyond the standard (decorators, async/await). • The best part of it: It's all a development time illusion!
  • 11. Tooling Setup we need a development environment, right !?!
  • 12. Setup TypeScript You have several ways to install TypeScript (globally and locally): http://www.typescriptlang.org/#Download
  • 13. Editor / IDE Grab a good code editor (better with TypeScript support, and provide the proper integration with your task runner of choice) • Visual Studio 2013, 2015+ • Visual Studio Code • Webstorm • Atom • Sublime • Eclipse • …
  • 14. Editor Setup (Visual Studio Code)
  • 15. TSC - the TypeScript compiler TSC is a source-to-source compiler (a transpiler). There are lots of options that allow you to: - concatenate different files in a single output file. - generate sourcemaps. - generate module loading code (node.js or require.js). You can play with the TypeScript playground or setup your environment to see it in action. tsc app.tsapp.ts app.js
  • 16. TSD - TypeScript Definition Files package manager TypeScript Definition File (ambient declaration file) • .d.ts extension. • Allows the definition of strong types. • Provide type definition for external JavaScript libraries. There's a community driven project on GitHub that tracks all of them: DefinitelyTyped (http://definitelytyped.org/) TSD: a specialized package manager to look for definition files inside DefinitelyTyped repository (http://definitelytyped.org/tsd/)
  • 17. Demo From JavaScript to TypeScript A quick overview!
  • 18. Types number, string, etc... all the standard JavaScript Types any: I can be any type, disable the type checking! void: I have no type at all (function return value)! enum / const enum: define enumerated values. <T>: casting! This is not a type conversion! type name = : define an alias for a type name. generics: great for code reuse! We can specify constraints if we want.
  • 19. Interfaces Interfaces are used to define the SHAPE of our objects! They are used to define Contracts within our code! TypeScript type checking is based on a concept called Structural Typing (or Duck Typing), which means the object shape / structure is the most important thing! Two different interfaces (objects) that expose the same properties are considered compatible. This mean you can assign 'apples' to 'oranges' under specific conditions.
  • 20. Interfaces Interfaces can describe: • Objects • Functions • Arrays / Dictionaries • Hybrid Types ('things' that are both objects and functions) Interfaces support: • Inheritance They do not support accessors (get / set): you need to convert the 'property' to a 'getProperty()' function if you wanna give that readonly behavior
  • 21. Classes Classes implement the behaviors of an entity. They have support for: • accessors (get, set) [ES5+] • modifiers: public, private, protected • constructor • inheritable • static properties • abstract (class & methods) • interface implementation Classes also define Types, they have two sides: • instance side (the properties involved in structural type checking) • static side (constructor and static properties, not involved in the type checking)
  • 22. Classes - Pay Attention to... The 'this': most of the times it represents the instance of the class itself (like in C#). The 'this' has a different meaning in function expression and when using the 'arrow syntax': • function() { … }: this act exactly as expected in strict mode (it can be undefined or whatever it was when entering the function execution context). • () => { … }: this always refers to the class instance. Composition / Encapsulation patterns: don't mess up with the this! Always delegate the function call properly, that is: call the function on its original object rather than assigning the pointer to the function to another variable!
  • 23. Namespace & Module • Namespaces and Modules are used to add more structuring to your code. • Group and Organize objects based on their behavior or because they are related to each other in some way (i.e.: all the classes of a specific feature, a library, etc...). • Allow to split your code in multiple files.
  • 24. Namespace Also called 'internal module': • export: decide what to expose to the outside world. • can be split in multiple files. How to use: • build the whole application concatenating all the files. • reference the files using <script> tags in the correct order. NO DYNAMIC MODULE LOADING (Node.js / Require.js)
  • 25. Module Also called 'external module': • export: decide what to expose to the outside world. • have file scope! (map 1:1 with the files that define it). • any file containing a top-level import or export is considered a module. • must use the '--module' compiler switch [commonjs, AMD, system, ...]. How to use: • Reference them using the 'import' keyword and assign a name alias. • Node.js / Require.js dynamic module loaders.
  • 26. Decorators (ES7 proposal) Decorators make it possible to annotate and modify classes and properties at design time. A decorator is: • an expression • that evaluates to a function • that takes the target, name, and property descriptor as arguments • and optionally returns a property descriptor to install on the target object In TypeScript we have 4 types of decorators: • ClassDecorator • MethodDecorator • PropertyDecorator • ParameterDecorator
  • 27. Various / Advanced TypeScript also has support for many more ES6 features: • Let / const • Destructuring declarations • For..of • Template strings • Generators • Class expressions And some language specific / custom extensions: • Tuple types • Union types • Intersection types • Decorators (ES7 proposal) • Async / await
  • 29.
  • 30. Thanks All! I hope you enjoyed the session! Let’s stay in touch!
  • 31. Q. & A. "Speak now or forever hold your peace!"
  • 32. License This work is published under: Creative Commons Attribution NonCommercial ShareAlike 3.0 License http://creativecommons.org/licenses/by-nc-sa/3.0/

Hinweis der Redaktion

  1. Our story / relationship with JavaScript began when we decided how to develop the next version of our signature application, we decided to go for: - microservices - DDD / CQRS  / ES - web front end<- it turned out that with the same technologies we could also create stand alone apps.
  2. TypeScript = JavaScript + Static Types +Code Encapsulation (Modularity) There are also other approaches: Dart / CoffeeScript other languages that compile to JavaScript too. Every language is just a layer on top of another layer (on top of another layer) down to the assembly code!
  3. if you intall it manually: install Node.js (https://nodejs.org/en/)​ from a console prompt: npm install -g typescript​ check for the proper version to be installed (tsc -v) eventually fix the path environment variables​
  4. Let's consider a typical situation
  5. Interfaces are used to define the SHAPE of our objects!​ Interface IPersonalData{​    Id: number,​    Name: string,​    ...​ }​ ​ An Interface can describe a function:​ interface loggingFunction{​ (message: string): void​ }​ An Interface can describe an array / dictionary:​ interface StringDictionary {​ [index: string]: string; // index can be number or string​ }​ ​ An Interface can describe an hybrid type:​ interface Timer {​ (interval: number): string;​ interval: number;​ reset(): void;​ }​ ​ ​