SlideShare a Scribd company logo
1 of 37
LEARNING



TypeScript                  PART 1


     2013,
     WWW.DIGITALMINDIGNITION.COM,
     ALEXANDRE MARREIROS
Learning
About
    Alexandre Marreiros
        • CTO @ INNOVAGENCY
        • Tech Trainner, Speaker & Consultant as Independent


        Contacts
        • amarreiros@gmail.com
        • @alexmarreiros
        • www.digitalmindignition.com
Learning
What is TypeScript
―TypeScript is a superset of Javascript which primarily
provides static typing, classes and interfaces. One of the big
benefits is to enable IDEs to provide a richer environment for spotting
common errors as you type the code. Other benefits can be having all the
best things of javascript in a strong type language. Is also a Codeplex
initiative.‖
                                                                  Paul Dixon

TypeScript is a language for application-scale JavaScript
development.
TypeScript is a typed superset of JavaScript that compiles to
plain JavaScript.
Learning
Why use TypeScript
For a large Javascript project, adopting Typescript might result in
more robust software, while still being deployable where a regular
javascript application would run.


To easy build clean and mantainable code (costum javascript
programming can sometimes become messy if you don‘t apply
pattern‘s ).


TypeScript allow us to create encapsulation.
Learning
Review JavaScript Types
• JavaScript Type System is dynamic
• Dynamic Type System provide us with:
  – Variables can hold any object
  – Types are determined at the runtime
  – Is impossible to ensure right conversion of types or if the types are passed
    in the right way, at the development time
Learning
JavaScript Language
• Client side language
• Not compiled
• Dynamic typed
• Not Object Oriented
• Procedure language


   The mindset of a cliente side language is diferente from the mindset of a server side
 language. Large enterprise programs need developer‘s to know the two worlds and made
                 that worlds interact to build the aplication experience.
Learning
TypeScript & JavaScript
                           TypeScript Provide us with:

                           •   JavaScript Abstration
                           •   Works on Any Browser
                 Produce   •   Works on Any host
                           •   Works in Any OS
Abstraction                •   Tool Support




                                        Is possible to use standard
                                        JavaScript when coding in
                                        TypeScript language
Learning
TypeScript Fundamentals
       Object Oriented
                                          Static Typing                Encapsulation




                                Modules                                           Classes




  Compiled                                                              Intelisense
                 Contructors,
  Language                          Lambda                Interfaces      Syntax
                  Functions,
(Compiles to                       Functions                             checking
                  Properties
 JavaScript)
Learning
      TypeScript Language first contact

                             Compile


Class Message{                         Var Message = (function(){
  innerMsg:string;                           function Message(msg){
                                                 this.innerMsg= msg;
  constructor(msg:string){                   }
     thid.innerMsg=msg                     Message.prototype.ShowMSG =
   }                                           function (){
  ShowMsg(){                                     return ―test‖ + this.innerMsg
     return ―test‖ +                         }
innerMsg;                                    return Message
  }                                    })();
}

      File.ts                                    File.js
Learning
TypeScript Language
• Don‘ t Forget TypeScript is a superste of JavaScript so what is
  supported by javascript syntax is supported by TypeScript.
• A scope of a codeblock is limited by {}
• A codeblock ends with ;
• All ecma script defined keywords are suported and means the
  same in TypeScript
Learning
            TypeScript Language




http://weblogs.asp.net/dwahlin/default.aspx
Learning
           TypeScript Language code hierarchy
                                                             Defines a naming container, that can export
                                             Module
                                                             diferent members

                                                   0..*
Defines a group of                                           Is a construct that enables you to create
behaviours associated   Interface             Class          your own custom types.
with a concept                      0..*
                                                      0..*
                                              Fields
                                           Constructor
                                            Functions
                                            Members
                                            Properties
     Implement

     Contains
Learning
           Play with TypeScript




http://www.typescriptlang.org/Playground/
Learning
TypeScript Tools support
• Sublime;
• Emacs;
• Vi
• Visual Studio
• TypeScript Playground
Learning
TypeScript Syntax
Variable Declaration:
• Type inference
  – Var xpto = 2;

  ( declare give a name set value , the type will be infered from the right
  operator parammeter)

• Type Annotation
  – Var xpto: number = 2;

  (declare give a name set the type set the value)
Learning
TypeScript Syntax
Variable Declaration examples:
• Type inference
  – Var xpto1;
     xpto1 = ‗test‘
  ( declare give a name, the type will be infered from the set that is done in
  the second line)

  – Var xpto = 2 + ‗this is a test‘;

  ( declare give a name set value , the type will be infered from the right
  operator parammeter, since the right parameter is a number concat with a
  string the runtime will assume xpto is a string )
Learning
TypeScript Syntax
Ambient Variable Declaration:
• To get a declared variable of a included file we can use the
  TypeScript declare
      declare var document



  (lib.d.ts is referenced by default in TypeScript and has references for the
  DOM tree and javascript functions)
  (jquery.d.ts is a file where we can reference the jquery library)
Learning
TypeScript Syntax
Use variables of other modules and having intellisence:
• Firt you should have your d.ts file in a known place
• Second you should reference the file like
• Third declare the type instance you want to use



                      ///<reference path=―jquery.d.ts‖>
                                declare var $;
Learning
TypeScript Syntax
The keyword any
• Any is the language primitive used to decorate a variable in a
  way that he can assume any type. When you declare a variable
  like this no static type validation will be done.
      var str: any;
The keyword null
• Except void and undefined null is the value who can set any type
  meaning theres no value in that instance type
The keyword undefined
• Represnts the same as null but with a diferente semantic
  mean, undefinded says that the variable wasn t iniciated yet
Learning
TypeScript Syntax
Primitive Types
                                              any
(The Any type is used to represent any JavaScript value. A value of the Any type supports the
same operations as a value in JavaScript and no static type checking)

                                            number
(The Number primitive type corresponds to the similarly named JavaScript primitive type and
represents double-precision 64-bit format IEEE 754 floating point values.)

                                             string
(The String primitive type corresponds to the similarly named JavaScript primitive type and
represents sequences of characters stored as Unicode UTF-16 code units..)
Learning
TypeScript Syntax
Primitive Types
                                                 null
(The Null type is a subtype of all types, except the Void and Undefined types. This means that
null is considered a valid value for all primitive and object types, including even the Number and
Boolean primitive types)

                                         undefined
(The Undefined type corresponds to the similarly named JavaScript primitive type and is the
type of the undefined literal.)

                                            Type Arrays
(Represents a container of values of a specific static or dynamic type. In the second case we ca
illustrate with the following example:
         var names: string[] = [‗Antonio‘,‘John‘,‘Manuel‘];
To índex the array you use the following notation
         names[num] ;
Where num is the índex in the array starting at 0 for the first elemento)
Learning
           Play with TypeScript




http://www.typescriptlang.org/Playground/
Learning
TypeScript Syntax
                                    TypeScript



        Dynamic Approach                               Static Aproach



  Dynamic Typing (type inference)                       Static Typing



      Evaluated at runtime                  Evaluated at compile time is type safe



       Just like JavaScript
Learning
TypeScript Syntax
Object Types


• Can be functions, class, module, interface, literal
• Canbe a container of Properties (public or private, required or
  optional) call signatures, Contruct Signatures, Index Signatures

                                        Examples


                                                              Var
  Var square:object = {x:100,y:100;};         sum:object=function(first:number, sec:
                                                   number){return first+sec;};
Learning
TypeScript Function Type
• Declare functions
  – var squareAreaFunc = function (h:number , w:number){
                            return h * w;
                    }                                         Emit the same
                                                                      JavaScript
• Using arrow functions
  – var squareAreaFunc = (h:number, w:number) => h*w;

• Option parameter
  – var Hthere = (str?:string) => alert( name|| ‗no name‘);

• Void keyword
      var squareAreaFunc = (h:number, w:number) => void;
Learning
Play with TypeScript
Learning
Typscript Interface Functions
• Interfaces provide the ability to give names to object types and
  the ability to compose existing named object types into new ones.
• Interfaces have no run-time representation—they are purely a
  compile-time construct.
• Use the keyword extends to build a interface
                                                 interface Mover
that extends other interface.                    {
                                                   move(): void;
                                                   getStatus(): { speed: number; };
                                                 }
        var Moverobj:Mover =
        {
          move: function() {….},                  Declare a interface
          getStatus:function(){…}
        }                                         Implement a interface
Learning
Play with TypeScript
Learning
TypeScript Classes
• A class is a container
• His a role is encapsulate code and variables in a encapsolated
  concept
Learning
TypeScript Classes
• To define a Class
      class Person {


      }
• Constructors are used to initialize class instances                  If you use the
                                                                    keyword public in a
      Class Person {
                                                                        constructor
             engine: string;                                        parameter you dont
             construct (engine : string ){ this.engine = engine;}   need to declare the
                                                                            field
      }
Learning
TypeScript Classes
• Instantiate a new instance of a class
       var Personinst = new Person (‗test‘);
• Field members in typescript are public by default but we can change
  the visibility
       class Person {
               private engine:string;
       }


• Properties allow you to get or set members value            TypeScript supports
                                                                ComplexTypes
       get myEngine:string { return this.engine;}
Learning
            TypeScript Classes
            • Cast between 2 types
                      var table: HTMLTableElement =<HTMLTableElement>
                                                       document.createElement(‗table‘);

                                                                                                           TypeScript knows
                                                                                                            what types exist
                                                                                                           with the reference
                                                                                                           of type definition
                                                                                                                  files




You can find a lot of type definition files for third party libraries at https://github.com/borisyankov/DefinitelyTyped
Learning
TypeScript Extending Classes
                         Animal


                                              inheritance

                 Bird                  Cat


• TypeScript defines the keyword extends as a way to allow types
  to extend other thypes
      class Bird extends Anima{
                                                            You have to
            constructor(){ super();}                        call the base
      }                                                         class
                                                             constructor
Learning
TypeScript Interfaces and Classes
• TypeScript defines the keyword implements as a way to allow
  types to ―sign‖ a interface contract
      class Bird implements IAnimal ….


(Note: Consider that IAnimal is a interface that defines the
contract associated to a Animal)
• The rules to use Interfaces in a Typescript are similar to the
  rules of .NET or JAVA
Learning
Play with TypeScript
Learning

      Questions

      Your turn to talk, if you have any question




                                            feel free to ask
Learning

            References
  • http://www.typescriptlang.org/
  • http://www.typescriptlang.org/Content/TypeScript%20Language
    %20Specification.pdf
  • http://www.sellsbrothers.com/posts/Details/12724
  • http://typescript.codeplex.com/
  • http://weblogs.asp.net/dwahlin/default.aspx
  • http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-
    TypeScript

More Related Content

What's hot

Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to AdvancedTalentica Software
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practicesIwan van der Kleijn
 
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
 
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)
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSRafael Casuso Romate
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipesKnoldus Inc.
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsNewCircle Training
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)Scott Wlaschin
 

What's hot (20)

TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
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
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJS
 
C# String
C# StringC# String
C# String
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipes
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Angular
AngularAngular
Angular
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)
 

Viewers also liked

Typescript - MentorMate Academy
Typescript - MentorMate AcademyTypescript - MentorMate Academy
Typescript - MentorMate AcademyDimitar Danailov
 
Introduction about type script
Introduction about type scriptIntroduction about type script
Introduction about type scriptBinh Quan Duc
 
Building End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptBuilding End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptGil Fink
 
Introduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicIntroduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicSmartLogic
 
Introduction to Angular with TypeScript for .NET Developers
Introduction to Angular with TypeScript for .NET DevelopersIntroduction to Angular with TypeScript for .NET Developers
Introduction to Angular with TypeScript for .NET DevelopersLaurent Duveau
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introductionBob German
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScriptBob German
 
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 2Knoldus Inc.
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviWinston Levi
 

Viewers also liked (11)

Typescript - MentorMate Academy
Typescript - MentorMate AcademyTypescript - MentorMate Academy
Typescript - MentorMate Academy
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Introduction about type script
Introduction about type scriptIntroduction about type script
Introduction about type script
 
Building End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptBuilding End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScript
 
Introduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogicIntroduction to Type Script by Sam Goldman, SmartLogic
Introduction to Type Script by Sam Goldman, SmartLogic
 
Type script
Type scriptType script
Type script
 
Introduction to Angular with TypeScript for .NET Developers
Introduction to Angular with TypeScript for .NET DevelopersIntroduction to Angular with TypeScript for .NET Developers
Introduction to Angular with TypeScript for .NET Developers
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introduction
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
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
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston Levi
 

Similar to Learning typescript (20)

TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
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
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
Typescript Basics
Typescript BasicsTypescript Basics
Typescript Basics
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
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
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Type script
Type scriptType script
Type script
 
Type script
Type scriptType script
Type script
 
Python with data Sciences
Python with data SciencesPython with data Sciences
Python with data Sciences
 
Memory models in c#
Memory models in c#Memory models in c#
Memory models in c#
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
3. jvm
3. jvm3. jvm
3. jvm
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 

More from Alexandre Marreiros

Xamarin devdays 2017 - PT - connected apps
Xamarin devdays 2017 - PT - connected appsXamarin devdays 2017 - PT - connected apps
Xamarin devdays 2017 - PT - connected appsAlexandre Marreiros
 
ASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a coupleASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a coupleAlexandre Marreiros
 
Jws masterclass progressive web apps
Jws masterclass progressive web appsJws masterclass progressive web apps
Jws masterclass progressive web appsAlexandre Marreiros
 
Quick View of Angular JS for High School
Quick View of Angular JS for High SchoolQuick View of Angular JS for High School
Quick View of Angular JS for High SchoolAlexandre Marreiros
 
Pt xug xamarin pratices on big ui consumer apps
Pt xug  xamarin pratices on big ui consumer appsPt xug  xamarin pratices on big ui consumer apps
Pt xug xamarin pratices on big ui consumer appsAlexandre Marreiros
 
Gab2015 azure search as a service
Gab2015 azure search as a serviceGab2015 azure search as a service
Gab2015 azure search as a serviceAlexandre Marreiros
 
Pragmatic responsive web design industry session 7
Pragmatic responsive web design   industry session 7Pragmatic responsive web design   industry session 7
Pragmatic responsive web design industry session 7Alexandre Marreiros
 
Universal Apps Development using HTML 5 and WINJS
Universal Apps Development using HTML 5 and WINJSUniversal Apps Development using HTML 5 and WINJS
Universal Apps Development using HTML 5 and WINJSAlexandre Marreiros
 
Windows8.1 html5 dev paradigm discussion netponto
Windows8.1 html5 dev paradigm discussion netpontoWindows8.1 html5 dev paradigm discussion netponto
Windows8.1 html5 dev paradigm discussion netpontoAlexandre Marreiros
 

More from Alexandre Marreiros (20)

Agular fromthetrenches2netponto
Agular fromthetrenches2netpontoAgular fromthetrenches2netponto
Agular fromthetrenches2netponto
 
Whats a Chat bot
Whats a Chat botWhats a Chat bot
Whats a Chat bot
 
Type of angular 2
Type of angular 2Type of angular 2
Type of angular 2
 
Xamarin devdays 2017 - PT - connected apps
Xamarin devdays 2017 - PT - connected appsXamarin devdays 2017 - PT - connected apps
Xamarin devdays 2017 - PT - connected apps
 
ASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a coupleASP.NEt MVC and Angular What a couple
ASP.NEt MVC and Angular What a couple
 
Angular 2
Angular 2Angular 2
Angular 2
 
Jws masterclass progressive web apps
Jws masterclass progressive web appsJws masterclass progressive web apps
Jws masterclass progressive web apps
 
Xamarin.forms
Xamarin.forms Xamarin.forms
Xamarin.forms
 
Quick View of Angular JS for High School
Quick View of Angular JS for High SchoolQuick View of Angular JS for High School
Quick View of Angular JS for High School
 
Pt xug xamarin pratices on big ui consumer apps
Pt xug  xamarin pratices on big ui consumer appsPt xug  xamarin pratices on big ui consumer apps
Pt xug xamarin pratices on big ui consumer apps
 
Get satrted angular js day 2
Get satrted angular js day 2Get satrted angular js day 2
Get satrted angular js day 2
 
Get satrted angular js
Get satrted angular jsGet satrted angular js
Get satrted angular js
 
Gab2015 azure search as a service
Gab2015 azure search as a serviceGab2015 azure search as a service
Gab2015 azure search as a service
 
Pragmatic responsive web design industry session 7
Pragmatic responsive web design   industry session 7Pragmatic responsive web design   industry session 7
Pragmatic responsive web design industry session 7
 
Boot strapandresponsiveintro
Boot strapandresponsiveintroBoot strapandresponsiveintro
Boot strapandresponsiveintro
 
WebSite development using WinJS
WebSite development using WinJSWebSite development using WinJS
WebSite development using WinJS
 
Universal Apps Development using HTML 5 and WINJS
Universal Apps Development using HTML 5 and WINJSUniversal Apps Development using HTML 5 and WINJS
Universal Apps Development using HTML 5 and WINJS
 
GWAB Mobile Services
GWAB Mobile ServicesGWAB Mobile Services
GWAB Mobile Services
 
Html5ignition newweborder
Html5ignition newweborderHtml5ignition newweborder
Html5ignition newweborder
 
Windows8.1 html5 dev paradigm discussion netponto
Windows8.1 html5 dev paradigm discussion netpontoWindows8.1 html5 dev paradigm discussion netponto
Windows8.1 html5 dev paradigm discussion netponto
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Learning typescript

  • 1. LEARNING TypeScript PART 1 2013, WWW.DIGITALMINDIGNITION.COM, ALEXANDRE MARREIROS
  • 2. Learning About Alexandre Marreiros • CTO @ INNOVAGENCY • Tech Trainner, Speaker & Consultant as Independent Contacts • amarreiros@gmail.com • @alexmarreiros • www.digitalmindignition.com
  • 3. Learning What is TypeScript ―TypeScript is a superset of Javascript which primarily provides static typing, classes and interfaces. One of the big benefits is to enable IDEs to provide a richer environment for spotting common errors as you type the code. Other benefits can be having all the best things of javascript in a strong type language. Is also a Codeplex initiative.‖ Paul Dixon TypeScript is a language for application-scale JavaScript development. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
  • 4. Learning Why use TypeScript For a large Javascript project, adopting Typescript might result in more robust software, while still being deployable where a regular javascript application would run. To easy build clean and mantainable code (costum javascript programming can sometimes become messy if you don‘t apply pattern‘s ). TypeScript allow us to create encapsulation.
  • 5. Learning Review JavaScript Types • JavaScript Type System is dynamic • Dynamic Type System provide us with: – Variables can hold any object – Types are determined at the runtime – Is impossible to ensure right conversion of types or if the types are passed in the right way, at the development time
  • 6. Learning JavaScript Language • Client side language • Not compiled • Dynamic typed • Not Object Oriented • Procedure language The mindset of a cliente side language is diferente from the mindset of a server side language. Large enterprise programs need developer‘s to know the two worlds and made that worlds interact to build the aplication experience.
  • 7. Learning TypeScript & JavaScript TypeScript Provide us with: • JavaScript Abstration • Works on Any Browser Produce • Works on Any host • Works in Any OS Abstraction • Tool Support Is possible to use standard JavaScript when coding in TypeScript language
  • 8. Learning TypeScript Fundamentals Object Oriented Static Typing Encapsulation Modules Classes Compiled Intelisense Contructors, Language Lambda Interfaces Syntax Functions, (Compiles to Functions checking Properties JavaScript)
  • 9. Learning TypeScript Language first contact Compile Class Message{ Var Message = (function(){ innerMsg:string; function Message(msg){ this.innerMsg= msg; constructor(msg:string){ } thid.innerMsg=msg Message.prototype.ShowMSG = } function (){ ShowMsg(){ return ―test‖ + this.innerMsg return ―test‖ + } innerMsg; return Message } })(); } File.ts File.js
  • 10. Learning TypeScript Language • Don‘ t Forget TypeScript is a superste of JavaScript so what is supported by javascript syntax is supported by TypeScript. • A scope of a codeblock is limited by {} • A codeblock ends with ; • All ecma script defined keywords are suported and means the same in TypeScript
  • 11. Learning TypeScript Language http://weblogs.asp.net/dwahlin/default.aspx
  • 12. Learning TypeScript Language code hierarchy Defines a naming container, that can export Module diferent members 0..* Defines a group of Is a construct that enables you to create behaviours associated Interface Class your own custom types. with a concept 0..* 0..* Fields Constructor Functions Members Properties Implement Contains
  • 13. Learning Play with TypeScript http://www.typescriptlang.org/Playground/
  • 14. Learning TypeScript Tools support • Sublime; • Emacs; • Vi • Visual Studio • TypeScript Playground
  • 15. Learning TypeScript Syntax Variable Declaration: • Type inference – Var xpto = 2; ( declare give a name set value , the type will be infered from the right operator parammeter) • Type Annotation – Var xpto: number = 2; (declare give a name set the type set the value)
  • 16. Learning TypeScript Syntax Variable Declaration examples: • Type inference – Var xpto1; xpto1 = ‗test‘ ( declare give a name, the type will be infered from the set that is done in the second line) – Var xpto = 2 + ‗this is a test‘; ( declare give a name set value , the type will be infered from the right operator parammeter, since the right parameter is a number concat with a string the runtime will assume xpto is a string )
  • 17. Learning TypeScript Syntax Ambient Variable Declaration: • To get a declared variable of a included file we can use the TypeScript declare declare var document (lib.d.ts is referenced by default in TypeScript and has references for the DOM tree and javascript functions) (jquery.d.ts is a file where we can reference the jquery library)
  • 18. Learning TypeScript Syntax Use variables of other modules and having intellisence: • Firt you should have your d.ts file in a known place • Second you should reference the file like • Third declare the type instance you want to use ///<reference path=―jquery.d.ts‖> declare var $;
  • 19. Learning TypeScript Syntax The keyword any • Any is the language primitive used to decorate a variable in a way that he can assume any type. When you declare a variable like this no static type validation will be done. var str: any; The keyword null • Except void and undefined null is the value who can set any type meaning theres no value in that instance type The keyword undefined • Represnts the same as null but with a diferente semantic mean, undefinded says that the variable wasn t iniciated yet
  • 20. Learning TypeScript Syntax Primitive Types any (The Any type is used to represent any JavaScript value. A value of the Any type supports the same operations as a value in JavaScript and no static type checking) number (The Number primitive type corresponds to the similarly named JavaScript primitive type and represents double-precision 64-bit format IEEE 754 floating point values.) string (The String primitive type corresponds to the similarly named JavaScript primitive type and represents sequences of characters stored as Unicode UTF-16 code units..)
  • 21. Learning TypeScript Syntax Primitive Types null (The Null type is a subtype of all types, except the Void and Undefined types. This means that null is considered a valid value for all primitive and object types, including even the Number and Boolean primitive types) undefined (The Undefined type corresponds to the similarly named JavaScript primitive type and is the type of the undefined literal.) Type Arrays (Represents a container of values of a specific static or dynamic type. In the second case we ca illustrate with the following example: var names: string[] = [‗Antonio‘,‘John‘,‘Manuel‘]; To índex the array you use the following notation names[num] ; Where num is the índex in the array starting at 0 for the first elemento)
  • 22. Learning Play with TypeScript http://www.typescriptlang.org/Playground/
  • 23. Learning TypeScript Syntax TypeScript Dynamic Approach Static Aproach Dynamic Typing (type inference) Static Typing Evaluated at runtime Evaluated at compile time is type safe Just like JavaScript
  • 24. Learning TypeScript Syntax Object Types • Can be functions, class, module, interface, literal • Canbe a container of Properties (public or private, required or optional) call signatures, Contruct Signatures, Index Signatures Examples Var Var square:object = {x:100,y:100;}; sum:object=function(first:number, sec: number){return first+sec;};
  • 25. Learning TypeScript Function Type • Declare functions – var squareAreaFunc = function (h:number , w:number){ return h * w; } Emit the same JavaScript • Using arrow functions – var squareAreaFunc = (h:number, w:number) => h*w; • Option parameter – var Hthere = (str?:string) => alert( name|| ‗no name‘); • Void keyword var squareAreaFunc = (h:number, w:number) => void;
  • 27. Learning Typscript Interface Functions • Interfaces provide the ability to give names to object types and the ability to compose existing named object types into new ones. • Interfaces have no run-time representation—they are purely a compile-time construct. • Use the keyword extends to build a interface interface Mover that extends other interface. { move(): void; getStatus(): { speed: number; }; } var Moverobj:Mover = { move: function() {….}, Declare a interface getStatus:function(){…} } Implement a interface
  • 29. Learning TypeScript Classes • A class is a container • His a role is encapsulate code and variables in a encapsolated concept
  • 30. Learning TypeScript Classes • To define a Class class Person { } • Constructors are used to initialize class instances If you use the keyword public in a Class Person { constructor engine: string; parameter you dont construct (engine : string ){ this.engine = engine;} need to declare the field }
  • 31. Learning TypeScript Classes • Instantiate a new instance of a class var Personinst = new Person (‗test‘); • Field members in typescript are public by default but we can change the visibility class Person { private engine:string; } • Properties allow you to get or set members value TypeScript supports ComplexTypes get myEngine:string { return this.engine;}
  • 32. Learning TypeScript Classes • Cast between 2 types var table: HTMLTableElement =<HTMLTableElement> document.createElement(‗table‘); TypeScript knows what types exist with the reference of type definition files You can find a lot of type definition files for third party libraries at https://github.com/borisyankov/DefinitelyTyped
  • 33. Learning TypeScript Extending Classes Animal inheritance Bird Cat • TypeScript defines the keyword extends as a way to allow types to extend other thypes class Bird extends Anima{ You have to constructor(){ super();} call the base } class constructor
  • 34. Learning TypeScript Interfaces and Classes • TypeScript defines the keyword implements as a way to allow types to ―sign‖ a interface contract class Bird implements IAnimal …. (Note: Consider that IAnimal is a interface that defines the contract associated to a Animal) • The rules to use Interfaces in a Typescript are similar to the rules of .NET or JAVA
  • 36. Learning Questions Your turn to talk, if you have any question feel free to ask
  • 37. Learning References • http://www.typescriptlang.org/ • http://www.typescriptlang.org/Content/TypeScript%20Language %20Specification.pdf • http://www.sellsbrothers.com/posts/Details/12724 • http://typescript.codeplex.com/ • http://weblogs.asp.net/dwahlin/default.aspx • http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing- TypeScript