SlideShare ist ein Scribd-Unternehmen logo
1 von 36
TypeScript
intro
19.03.2015 @Tallinn
Warning & credentials
Slidesare mostly based on:
–Sander Mak typescript-coding-javascript-
without-the-pain
–Anders Hejlsberg's video on homepage:
www.typescriptlang.org
Slides are packed with text
–Meant for
recalling the presentation
people not attending the presentation
–You might not want to read the slides ifYou
Agenda
WhyTypeScript
Language intro
Demos
https://github.com/atsu85/TypeScriptPlayField
– TypeScript language features
– TypeScript in Angular project (tiny sample)
Comparison withTS alternatives
Conclusion
What’s good about JS?
It’s everywhere
– Browsers, servers
Huge amount of libraries
Flexible
procedural and functional
What’s wrong with JS?
Dynamic typing
– Can’t do type checking (but lints could help a bit)
– Content-assist can’t be automatically provided for IDE’s
Lack of modularity (out of the box)
Verbose patterns
IIFE - Immediately-invoked_function_expression
Declaring/extending classes/objects
Wishlist
Scalable HTML5 client side development
– Modularity
– Safe Refactoring
Type checking
Searching for method/filed usages
Easily learnable for Java developers
Non-invasive
– Interop with existing libs
– browser support
Easy to debug
– Clean JS output (also for exit strategy)
– Map files (mapping from generated code to originaal source)
Long-term vision (Language spec, future standards)
EcmaScript 6 (ES6)
Current state
– RC2 (March 4, 2015)
Release?
– "A sixth edition of the standard is currently under
development with a target date of June 2015 for
completion"
ES6 language features with code samples:
– https://github.com/lukehoban/es6features
TypeScript project
Superset of JS(ES5) that compiles to JS
– Compiles to ES3/ES5/ES6
– No special runtime dependencies
– TypeScript 2.0 goal to be superset of ES6
Website: http://www.typescriptlang.org/
– https://github.com/Microsoft/TypeScript/wiki/Roadmap
Microsoft
– Anders Hejlsberg (Turbopascal, Delphy, C#,TypeScript)
– Working with Flow and Angular(AtScript) teams to become best choice for writing JS
OS compiler(also written inTS) and type declarations(JS core, DOM, …)
– https://github.com/Microsoft/TypeScript
– Apache 2.0 license
Uses NodeJS for compiling
– Cross platform, no MS dependencies
TS features from ES6…
Classes, inheritance
Interfaces
Arrow functions aka Lambdas
Default parameters, rest parameters (varargs)
Template strings
…TS features from ES6
TS v1.4 (with compile target=ES6, plans to also allow compiling following ES6
features to ES3/ES5)
– let, const
Roadmap:
TS v1.5
– destructuring
– for..of, iterators?
– unicode
– External module compatibility
– symbols
TS v1.6
– Generators
– async/await
TS 2.0 "plans"
– Superset of ES6
Getting started
Install node
InstallTypeScript: ´npm install -g typescript´
Rename extension: ´mv mycode.js mycode.ts´
Compile: ´tsc mycode.ts´
…Getting started - Got
compilation error?
Resolve errors related to global variables (i.e.
globalVar)
– declare var globalVar;
WhenYou don’t have type information (and don’t want to write it
Yourself)
– IfYou want type info about the global variable:
– See
https://github.com/borisyankov/DefinitelyTyped/
– Type definitions for almost 1000 libraries
declare var globalVar: someModule.SomeType;
Need to reference library or type declarations of the library
– /// <reference path=„path/to/my-lib.ts" />
– /// <reference path=„path/to/external-lib-type-info.d.ts" />
TypeScript language features
Syntax sugar for creating
– Classes, interfaces, modules, …
Types:
– Optional (in code, not in comments)
JS isTS – add types when needed
– Static
Errors at compile time not at runtime
– Interfaces, classes or structural
Can useType names, but they are not required
Checked at compile time, not runtime (unlike with „duck typing“)
– Disappear after compiling
TypeScript vs Java: Classes
Similar:
– Can implement interfaces
– Inheritance
– Instance methods/members
– Static methods/members
– Generics (with type erasure)
Different:
– No method/constructor overloading
– Default & optional parameters
– ES6 class syntax (similar to Scala)
– Mixins/traits (trivial, but no out-of-the-box syntax as in Scala)
TypeScript vs Java:Types
Object -> any
void -> void
boolean -> boolean
Integer, long, short, … -> number
String, char -> string
Arrays:
– TypeArray[] ->TypeArray[]
– primitiveTypeArray[] -> primitiveTypeArray[]
How it looks like?
var varName:VarType = … ;
function functionName(param1: Param1Type): RetrunType {
return new RetrunType(param1);
}
interface IPerson { name: string; getAge(): number;}
class Person implements IPerson {
constructor(public name: string, private yearOfBirth:
number){};
getAge() { // return type can be inferred
return new Date().getFullYear() - this.yearOfBirth; //
silly demo
}
}
Demo: Basics
Type annotations
Classes, interfaces, functions
– Optional/default members
– Optional/default function arguments
Errors when using missing field/function
Type inference
– From assignment
– From function return value to function return type
– From function declared parameter type to argument
passed to the function
Demo: Modules, Interfaces
Open-ended
–Can contribute classes/interfaces to a module
from another file
Can divide code into several files
–Can contribute members to interface from
another file
Very common for jQuery plugins
Modules can be imported using var:
–var demo = ee.iglu.demo;
–var obj = new demo.SomePublicClass();
Demo: Classes
Instance fields
Constructor
Private fields
– short notation for private fields (or fields with accessors)
Static fields
Default & optional parameters
Inheritence
Overriding/overloading
JS functions can’t be overloaded!
–one function must handle all diferent type
combinations, help from:
Default and optional parameters
Multiple signature definitions
Tricks with method signatures
Basically value-agnostic signatures:
interface Document {
createElement(tagName: „a"):
HTMLAnchorElement; createElement(tagName:
"div"): HTMLDivElement;
}
createElement("a").href = „/main“; // OK
createElement("div").href = „/main“; // ERROR div
doesn't have href
More useful stuff
Arrow functions a.k.a. Lambdas
Enums
Generics
– http://www.typescriptlang.org/Playground
Mixins/traits
– http://www.typescriptlang.org/Handbook#mixins
Union types, String interpolation
– http://www.typescriptlang.org/Playground: „New Features“
Avoid infering type to „any“ type:
– tsc --noImplicitAny superSolid.ts
TypeScript and external libs
Search forTypeScript declarations for the lib from
https://github.com/borisyankov/DefinitelyTyped/
contains type declarations for > 950 libs (~80 jQuery
plugins, 30 angular plugins, toastr, moment, fullCalendar,
pickadate)
http://www.typescriptlang.org/Handbook#writing-dts-files
Import type info from type declarations file:
/// <reference path=„path/to/external-lib-type-info.d.ts" />
Import type info fromTypeScript source file:
/// <reference path=„path/to/my-lib.ts" />
DEMO
– UsingTypeScript with AngularJS
Summary:TypeScriptType
System
Type inference and structural typing
– Very few type „annotations“ are necessary
Formalization of JS types
– Static representation of JS dynamic type system
Works with existing JS libs
– Out of the boxYou can treat any external JS lib object as „any“
type
– Declaration files can be writter and maintained separately
Not „provably type safe“
– Types reflect intent, but don't provide guarantees
Type declaration files can contain mistakes
Tools:TypeScript
Gradle:
– Compile: https://github.com/sothmann/typescript-gradle-plugin
– Monitor changes: https://github.com/bluepapa32/gradle-watch-plugin
Gulp (JS build tool)
– Compile: „gulp-type“ (incremental) and gulp-tsc
– Watch: gulp.watch()
Grunt (JS build tool): grunt-typescript, grunt-ts
Bower (JS dependency manager)
– „typescript“
TypeScript declarations managers:
– tsd, nuget
IDEs:VisualStudio, Eclipse(TypEcs, eclipse-typescript), WebStrom
TypeScript type definitions (*.d.ts)
dependency management
tsd:TypeScript Definition manager for DefinitelyTyped
– Install it:
npm install tsd@next –g
– Download latest definitions (recursively) and save dependency
to tsd.json:
tsd install angular-ui-router --save –r
>> written 2 files:
- angular-ui/angular-ui-router.d.ts
- angularjs/angular.d.tsSearch commit history angular
– Install specific revision of angular
tsd query angular –history
tsd install angular --commit 235f77 –save
– Cleanup & reinstall:
rm –rf typings
tsd reinstall
Demo: Internal modules
Declaration in „someLibrary.d.ts“:
module ee.iglu.demo {
export var publicVar = "Visible to outside";
var privateVar = "Not visible to outside";
export class PublicClass implements PublicType {
constructor(public someField: string) {
alert("privateVar: "+ privateVar);
}
}
}
Usage:
/// <reference path="../relative/path/to/someLibrary.d.ts" />
new ee.iglu.demo.PublicClass(„arg");
External modules
currently not ES6 compatible
– Commonjs (node)
File: myModule.ts
– /// <reference path="../typings/node.d.ts" />
– import http = module(„http“);
– export function myFunction(){…};
In another file in the same folder:
– import myModule = module(„./myModule“);
– myModule.myFunction();
– AMD (requireJS) – built on topp of commonJS
lazy loading
Verbose withoutTypeScript
TypeScript: interpreted mode
https://github.com/niutech/typescript-compile
–demo with angular
http://plnkr.co/edit/tahSo5uouPAcemjmXOEv?p=prev
ew
TypeScript vs Google Closure
Compiler
Google Closure Compiler:
– Pure JS +Types in JsDoc comments
– Focus on optimization, dead-code removal, minification
– Less expressive
– Warnings from static code analysis
TypeScript vs CoffeScript
Common:
– CAN compile to JS
Different:
– JS is NOT valid CoffeScript
– Dynamically typed
– Completely Different syntax for object literals, functions,
rest-args
More syntactic sugar
– No spec
– Doesn't track ES6
TypeScript vs Dart
Common:
– CAN compile to JS
Different:
– CAN run on DartVM
– Dart stdlib (collections/maps, etc)
– JS interop through dart:js lib
– Compiled JS is built for specific runtime (no good escape
strategy)
Who usesTypeScript?
Microsoft
Google (Angular team abandoned AtScript for
TypeScript)
Adobe
RedHat
LeapMotion
Walmart
Plantir
– Author of eclipse-typescript plugin
i have not managed to get working (twice) - my sugestion for Eclipse
isTypEcs
TypeScript - conclusion…
Still need to know some JS quirks
Not yet completely ES6 compatible
Non-MS tooling doesn't match yet the level of IDE
support offered for Java
– it is gradually improving, come and contribute!
TypeScript - …conclusion
Modules
Enums, Interfaces, Classes, inheritence
Generics
Optional types (gradual adoption & match forYour
comfort level):
– no type def-s - inferred type info from primitives, referenced
typedefs
– some type def-s - most types can be inferred
– -noImplicitAny - forces strongly typing
High value, low cost improvement over plain JS
– safer than JS
Solid path to ES6
The end (or start of the new
era?)
Your comments, thoughts…

Weitere ähnliche Inhalte

Was ist angesagt? (20)

.Net Core
.Net Core.Net Core
.Net Core
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
React js
React jsReact js
React js
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
TypeScript and Angular workshop
TypeScript and Angular workshopTypeScript and Angular workshop
TypeScript and Angular workshop
 
Type script - advanced usage and practices
Type script  - advanced usage and practicesType script  - advanced usage and practices
Type script - advanced usage and practices
 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascript
 

Andere mochten auch

Angular 2 with typescript
Angular 2 with typescriptAngular 2 with typescript
Angular 2 with typescriptTayseer_Emam
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core ConceptsFabio Biondi
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Knoldus Inc.
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2FITC
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviWinston Levi
 
Introduction à Angular 2
Introduction à Angular 2Introduction à Angular 2
Introduction à Angular 2Laurent Duveau
 
Angular 2 : le réveil de la force
Angular 2 : le réveil de la forceAngular 2 : le réveil de la force
Angular 2 : le réveil de la forceNicolas PENNEC
 
Introduction TypeScript
Introduction TypeScriptIntroduction TypeScript
Introduction TypeScriptfelixbillon
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript ModulesNoam Kfir
 

Andere mochten auch (14)

TypeScript
TypeScriptTypeScript
TypeScript
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Angular 2 with typescript
Angular 2 with typescriptAngular 2 with typescript
Angular 2 with typescript
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core Concepts
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with 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
 
Introduction à Angular 2
Introduction à Angular 2Introduction à Angular 2
Introduction à Angular 2
 
Angular 2 : le réveil de la force
Angular 2 : le réveil de la forceAngular 2 : le réveil de la force
Angular 2 : le réveil de la force
 
Introduction TypeScript
Introduction TypeScriptIntroduction TypeScript
Introduction TypeScript
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
 
Introduction à Angular 2
Introduction à Angular 2Introduction à Angular 2
Introduction à Angular 2
 

Ähnlich wie TypeScript intro

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
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!Alessandro Giorgetti
 
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
 
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.
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScriptOffirmo
 
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
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unitKotresh Munavallimatt
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0Michael Vorburger
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Christos Manios
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersRainer Stropek
 
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...Maarten Balliauw
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming WebStackAcademy
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...Maarten Balliauw
 

Ähnlich wie TypeScript intro (20)

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
 
TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!TypeScript . the JavaScript developer best friend!
TypeScript . the JavaScript developer best friend!
 
Type script
Type scriptType script
Type script
 
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
 
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
 
Angular2
Angular2Angular2
Angular2
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
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
 
Flow
FlowFlow
Flow
 
Type script
Type scriptType script
Type script
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
C#.net
C#.netC#.net
C#.net
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
Code Documentation. That ugly thing...
Code Documentation. That ugly thing...Code Documentation. That ugly thing...
Code Documentation. That ugly thing...
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ Developers
 
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
 

Kürzlich hochgeladen

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
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
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Kürzlich hochgeladen (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
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
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

TypeScript intro

  • 2. Warning & credentials Slidesare mostly based on: –Sander Mak typescript-coding-javascript- without-the-pain –Anders Hejlsberg's video on homepage: www.typescriptlang.org Slides are packed with text –Meant for recalling the presentation people not attending the presentation –You might not want to read the slides ifYou
  • 3. Agenda WhyTypeScript Language intro Demos https://github.com/atsu85/TypeScriptPlayField – TypeScript language features – TypeScript in Angular project (tiny sample) Comparison withTS alternatives Conclusion
  • 4. What’s good about JS? It’s everywhere – Browsers, servers Huge amount of libraries Flexible procedural and functional
  • 5. What’s wrong with JS? Dynamic typing – Can’t do type checking (but lints could help a bit) – Content-assist can’t be automatically provided for IDE’s Lack of modularity (out of the box) Verbose patterns IIFE - Immediately-invoked_function_expression Declaring/extending classes/objects
  • 6. Wishlist Scalable HTML5 client side development – Modularity – Safe Refactoring Type checking Searching for method/filed usages Easily learnable for Java developers Non-invasive – Interop with existing libs – browser support Easy to debug – Clean JS output (also for exit strategy) – Map files (mapping from generated code to originaal source) Long-term vision (Language spec, future standards)
  • 7. EcmaScript 6 (ES6) Current state – RC2 (March 4, 2015) Release? – "A sixth edition of the standard is currently under development with a target date of June 2015 for completion" ES6 language features with code samples: – https://github.com/lukehoban/es6features
  • 8. TypeScript project Superset of JS(ES5) that compiles to JS – Compiles to ES3/ES5/ES6 – No special runtime dependencies – TypeScript 2.0 goal to be superset of ES6 Website: http://www.typescriptlang.org/ – https://github.com/Microsoft/TypeScript/wiki/Roadmap Microsoft – Anders Hejlsberg (Turbopascal, Delphy, C#,TypeScript) – Working with Flow and Angular(AtScript) teams to become best choice for writing JS OS compiler(also written inTS) and type declarations(JS core, DOM, …) – https://github.com/Microsoft/TypeScript – Apache 2.0 license Uses NodeJS for compiling – Cross platform, no MS dependencies
  • 9. TS features from ES6… Classes, inheritance Interfaces Arrow functions aka Lambdas Default parameters, rest parameters (varargs) Template strings
  • 10. …TS features from ES6 TS v1.4 (with compile target=ES6, plans to also allow compiling following ES6 features to ES3/ES5) – let, const Roadmap: TS v1.5 – destructuring – for..of, iterators? – unicode – External module compatibility – symbols TS v1.6 – Generators – async/await TS 2.0 "plans" – Superset of ES6
  • 11. Getting started Install node InstallTypeScript: ´npm install -g typescript´ Rename extension: ´mv mycode.js mycode.ts´ Compile: ´tsc mycode.ts´
  • 12. …Getting started - Got compilation error? Resolve errors related to global variables (i.e. globalVar) – declare var globalVar; WhenYou don’t have type information (and don’t want to write it Yourself) – IfYou want type info about the global variable: – See https://github.com/borisyankov/DefinitelyTyped/ – Type definitions for almost 1000 libraries declare var globalVar: someModule.SomeType; Need to reference library or type declarations of the library – /// <reference path=„path/to/my-lib.ts" /> – /// <reference path=„path/to/external-lib-type-info.d.ts" />
  • 13. TypeScript language features Syntax sugar for creating – Classes, interfaces, modules, … Types: – Optional (in code, not in comments) JS isTS – add types when needed – Static Errors at compile time not at runtime – Interfaces, classes or structural Can useType names, but they are not required Checked at compile time, not runtime (unlike with „duck typing“) – Disappear after compiling
  • 14. TypeScript vs Java: Classes Similar: – Can implement interfaces – Inheritance – Instance methods/members – Static methods/members – Generics (with type erasure) Different: – No method/constructor overloading – Default & optional parameters – ES6 class syntax (similar to Scala) – Mixins/traits (trivial, but no out-of-the-box syntax as in Scala)
  • 15. TypeScript vs Java:Types Object -> any void -> void boolean -> boolean Integer, long, short, … -> number String, char -> string Arrays: – TypeArray[] ->TypeArray[] – primitiveTypeArray[] -> primitiveTypeArray[]
  • 16. How it looks like? var varName:VarType = … ; function functionName(param1: Param1Type): RetrunType { return new RetrunType(param1); } interface IPerson { name: string; getAge(): number;} class Person implements IPerson { constructor(public name: string, private yearOfBirth: number){}; getAge() { // return type can be inferred return new Date().getFullYear() - this.yearOfBirth; // silly demo } }
  • 17. Demo: Basics Type annotations Classes, interfaces, functions – Optional/default members – Optional/default function arguments Errors when using missing field/function Type inference – From assignment – From function return value to function return type – From function declared parameter type to argument passed to the function
  • 18. Demo: Modules, Interfaces Open-ended –Can contribute classes/interfaces to a module from another file Can divide code into several files –Can contribute members to interface from another file Very common for jQuery plugins Modules can be imported using var: –var demo = ee.iglu.demo; –var obj = new demo.SomePublicClass();
  • 19. Demo: Classes Instance fields Constructor Private fields – short notation for private fields (or fields with accessors) Static fields Default & optional parameters Inheritence
  • 20. Overriding/overloading JS functions can’t be overloaded! –one function must handle all diferent type combinations, help from: Default and optional parameters Multiple signature definitions
  • 21. Tricks with method signatures Basically value-agnostic signatures: interface Document { createElement(tagName: „a"): HTMLAnchorElement; createElement(tagName: "div"): HTMLDivElement; } createElement("a").href = „/main“; // OK createElement("div").href = „/main“; // ERROR div doesn't have href
  • 22. More useful stuff Arrow functions a.k.a. Lambdas Enums Generics – http://www.typescriptlang.org/Playground Mixins/traits – http://www.typescriptlang.org/Handbook#mixins Union types, String interpolation – http://www.typescriptlang.org/Playground: „New Features“ Avoid infering type to „any“ type: – tsc --noImplicitAny superSolid.ts
  • 23. TypeScript and external libs Search forTypeScript declarations for the lib from https://github.com/borisyankov/DefinitelyTyped/ contains type declarations for > 950 libs (~80 jQuery plugins, 30 angular plugins, toastr, moment, fullCalendar, pickadate) http://www.typescriptlang.org/Handbook#writing-dts-files Import type info from type declarations file: /// <reference path=„path/to/external-lib-type-info.d.ts" /> Import type info fromTypeScript source file: /// <reference path=„path/to/my-lib.ts" /> DEMO – UsingTypeScript with AngularJS
  • 24. Summary:TypeScriptType System Type inference and structural typing – Very few type „annotations“ are necessary Formalization of JS types – Static representation of JS dynamic type system Works with existing JS libs – Out of the boxYou can treat any external JS lib object as „any“ type – Declaration files can be writter and maintained separately Not „provably type safe“ – Types reflect intent, but don't provide guarantees Type declaration files can contain mistakes
  • 25. Tools:TypeScript Gradle: – Compile: https://github.com/sothmann/typescript-gradle-plugin – Monitor changes: https://github.com/bluepapa32/gradle-watch-plugin Gulp (JS build tool) – Compile: „gulp-type“ (incremental) and gulp-tsc – Watch: gulp.watch() Grunt (JS build tool): grunt-typescript, grunt-ts Bower (JS dependency manager) – „typescript“ TypeScript declarations managers: – tsd, nuget IDEs:VisualStudio, Eclipse(TypEcs, eclipse-typescript), WebStrom
  • 26. TypeScript type definitions (*.d.ts) dependency management tsd:TypeScript Definition manager for DefinitelyTyped – Install it: npm install tsd@next –g – Download latest definitions (recursively) and save dependency to tsd.json: tsd install angular-ui-router --save –r >> written 2 files: - angular-ui/angular-ui-router.d.ts - angularjs/angular.d.tsSearch commit history angular – Install specific revision of angular tsd query angular –history tsd install angular --commit 235f77 –save – Cleanup & reinstall: rm –rf typings tsd reinstall
  • 27. Demo: Internal modules Declaration in „someLibrary.d.ts“: module ee.iglu.demo { export var publicVar = "Visible to outside"; var privateVar = "Not visible to outside"; export class PublicClass implements PublicType { constructor(public someField: string) { alert("privateVar: "+ privateVar); } } } Usage: /// <reference path="../relative/path/to/someLibrary.d.ts" /> new ee.iglu.demo.PublicClass(„arg");
  • 28. External modules currently not ES6 compatible – Commonjs (node) File: myModule.ts – /// <reference path="../typings/node.d.ts" /> – import http = module(„http“); – export function myFunction(){…}; In another file in the same folder: – import myModule = module(„./myModule“); – myModule.myFunction(); – AMD (requireJS) – built on topp of commonJS lazy loading Verbose withoutTypeScript
  • 29. TypeScript: interpreted mode https://github.com/niutech/typescript-compile –demo with angular http://plnkr.co/edit/tahSo5uouPAcemjmXOEv?p=prev ew
  • 30. TypeScript vs Google Closure Compiler Google Closure Compiler: – Pure JS +Types in JsDoc comments – Focus on optimization, dead-code removal, minification – Less expressive – Warnings from static code analysis
  • 31. TypeScript vs CoffeScript Common: – CAN compile to JS Different: – JS is NOT valid CoffeScript – Dynamically typed – Completely Different syntax for object literals, functions, rest-args More syntactic sugar – No spec – Doesn't track ES6
  • 32. TypeScript vs Dart Common: – CAN compile to JS Different: – CAN run on DartVM – Dart stdlib (collections/maps, etc) – JS interop through dart:js lib – Compiled JS is built for specific runtime (no good escape strategy)
  • 33. Who usesTypeScript? Microsoft Google (Angular team abandoned AtScript for TypeScript) Adobe RedHat LeapMotion Walmart Plantir – Author of eclipse-typescript plugin i have not managed to get working (twice) - my sugestion for Eclipse isTypEcs
  • 34. TypeScript - conclusion… Still need to know some JS quirks Not yet completely ES6 compatible Non-MS tooling doesn't match yet the level of IDE support offered for Java – it is gradually improving, come and contribute!
  • 35. TypeScript - …conclusion Modules Enums, Interfaces, Classes, inheritence Generics Optional types (gradual adoption & match forYour comfort level): – no type def-s - inferred type info from primitives, referenced typedefs – some type def-s - most types can be inferred – -noImplicitAny - forces strongly typing High value, low cost improvement over plain JS – safer than JS Solid path to ES6
  • 36. The end (or start of the new era?) Your comments, thoughts…