SlideShare a Scribd company logo
1 of 32
Download to read offline
HOW WE MIGRATED OUR HUGE ANGULAR.JS
APP FROM COFFEESCRIPT TO TYPESCRIPT
Luka Zakrajšek
CTO @ Koofr
@bancek
Ljubljana Spring-ish JavaScript Meetup
February 10, 2015
ABOUT ME
FRI graduate
CTO and cofounder at Koofr
frontend, backend, iOS, Windows Phone
almost 3 years of Angular.js
KOOFR
Koofr is white-label cloud storage solution for ISPs
ANGULAR.JS AT KOOFR
web app
desktop application
(webappwrappedintobrowsertolooklikenative)
HUGE APP?
26 route controllers
90 directives
22 factories
14 filters
15 services
6012 LOC of Coffee (30 files)
2937 LOC of Angular HTML templates (101 files)
WE WERE HAPPY WITH COFFEESCRIPT
Pros
clean code
classes
Cons
technical debt
fear of refactoring
not enough tests
COFFEESCRIPT
Launched in 2010.
Gained traction with Rails support in 2011
$(function(){
//Initializationcodegoeshere
})
$->
#Initializationcodegoeshere
BROWSERIFY
Lets you require('modules') in the browser by bundling up all of your
dependencies.
varunique=require('uniq');
vardata=[1,2,2,3,4,5,5,5,6];
console.log(unique(data));
$npminstalluniq
$browserifymain.js-obundle.js
<scriptsrc="bundle.js"></script>
TYPESCRIPT
a typed superset of JavaScript that compiles to plain
JavaScript
any existing JavaScript program is also valid TypeScript
program
developed by Microsoft
from lead architect of C# and creator of Delphi and Turbo
Pascal
FIND A TYPO
classPoint{
x:number;
y:number;
constructor(x:number,y:number){
this.x=x;
this.y=y;
}
getDist(){
returnMath.sqrt(this.x*this.x+
this.y*this.y);
}
}
varp=newPoint(3,4);
vardist=p.getDst();
alert("Hypotenuseis:"+dist);
FEATURES
JAVASCRIPT
functionGreeter(greeting){
this.greeting=greeting;
}
Greeter.prototype.greet=function(){
return"Hello,"+this.greeting;
}
//Oops,we'repassinganobjectwhenwewantastring.
vargreeter=newGreeter({message:"world"});
alert(greeter.greet());
TYPES
functionGreeter(greeting:string){
this.greeting=greeting;
}
Greeter.prototype.greet=function(){
return"Hello,"+this.greeting;
}
vargreeter=newGreeter("world");
alert(greeter.greet());
CLASSES
classGreeter{
greeting:string;
constructor(message:string){
this.greeting=message;
}
greet(){
return"Hello,"+this.greeting;
}
}
vargreeter=newGreeter("world");
alert(greeter.greet());
TYPES
classAnimal{
constructor(publicname:string){}
move(meters:number){
alert(this.name+"moved"+meters+"m.");
}
}
classSnakeextendsAnimal{
constructor(name:string){super(name);}
move(){
alert("Slithering...");
super.move(5);
}
}
varsam:Animal=newSnake("SammythePython");
sam.move();
GENERICS
classGreeter<T>{
greeting:T;
constructor(message:T){
this.greeting=message;
}
greet(){
returnthis.greeting;
}
}
vargreeter=newGreeter<string>("Hello,world");
alert(greeter.greet());
MODULES
moduleSayings{
exportclassGreeter{
greeting:string;
constructor(message:string){
this.greeting=message;
}
greet(){
return"Hello,"+this.greeting;
}
}
}
vargreeter=newSayings.Greeter("world");
alert(greeter.greet());
USAGE
npminstall-gtypescript
tschelloworld.ts
<scriptsrc="helloworld.js"></script>
Or Grunt, Gulp ...
TOOLS
included in Visual Studio
JetBrains (IntelliJ)
Vim
Emacs
Sublime Text
CATS
MIGRATION
coffee-script-to-typescript to the rescue
npminstall-gcoffee-script-to-typescritpt
coffee-to-typescript-cmayour/files/*.coffee
EXISTING LIBRARIES
we use more than 30 libraries
to be completely type-safe,
you need definitions for all external libraries
DefinitelyTyped - more than 700 libraries
https://github.com/borisyankov/DefinitelyTyped
EXAMPLE
jgrowl.d.ts
///<referencepath="../jquery/jquery.d.ts"/>
interfaceJQueryStatic{
jGrowl:jgrowl.JGrowlStatic;
}
declaremodulejgrowl{
interfaceJGrowlOptions{
sticky?:boolean;
position?:string;
beforeOpen?:Function;
//...
}
interfaceJGrowlStatic{
(msg:string,options?:JGrowlOptions):void;
}
}
$.jGrowl({sticky:true,beforeOpen:()=>{
console.log("opening")}})
ANGULARJS - BEFORE
CoffeeScript
angular.module('comments.controllers',[]).directive('comments',->
restrict:'E'
scope:
mount:'='
replace:yes
templateUrl:'comments/comments.html'
controller:($scope,Api)->
$scope.comments=[]
$scope.load=->
Api.callApi.api.Comments.commentsRange($scope.mount.id,0,10
success:(res)->
$scope.comments=res.comments
$scope.load()
)
ANGULARJS - AFTER
TypeScript
///<referencepath="../app.ts"/>
modulecomments{
interfaceCommentsScopeextendsng.IScope{
mount:k.Mount
comments:Array<k.Comment>
load():void
}
exportclassCommentsCtrl{
constructor($scope:CommentsScope,Api:api.Api){
$scope.comments=[];
$scope.load=()=>{
Api.get(Api.api.Comments.commentsRange($scope.mount.id,0,
.then((res)=>{
$scope.comments=res.comments;
});
}
};
}
}
exportvarcommentsDirective:ng.IDirectiveFactory=()=>{
return{
restrict:"E",
scope:{
mount:"=",
appendComment:"="
},
replace:true,
templateUrl:"comments/comments.html",
controller:CommentsCtrl
};
};
}
PROJECT STRUCTURE
files/
comments/
utils/
...
app.ts
main.d.ts
typings.d.ts
PROJECT STRUCTURE
app.ts
///<referencepath="main.d.ts"/>
///<referencepath="files/index.ts"/>
///<referencepath="comments/index.ts"/>
///<referencepath="utils/index.ts"/>
exportvarmodule=angular.module("app",[
"gettext",
files.module.name,
comments.module.name,
utils.module.name
])
}
PROJECT STRUCTURE
comments/index.ts
///<referencepath="../app.ts"/>
///<referencepath="commentsDirective.ts"/>
modulecomments{
exportvarmodule=angular.module("comments",[])
.directive("comments",commentsDirective);
}
HOW TO TEST EVERYTHING?
code coverage to the rescue
usually used for test code coverage
we can use it to see which lines were covered by manually
"testing" the app
LIVECOVER
Notpublishedyet.WillbeonGitHubandnpm.
#GenerateannotatedJavaScriptcodewithBlanket.js
$simple-blanket-oapp-cover.jsapp.js
#RunLiveCoverserver
$livecover-p3000
<scriptsrc="http://localhost:3000/coverage.js"></script>
Open in your browser
and start clicking like crazy.
https://localhost:3000
QUESTIONS?

More Related Content

What's hot

Cross platform development
Cross platform developmentCross platform development
Cross platform development
dftaiwo
 

What's hot (20)

Mobile Applications with Angular 4 and Ionic 3
Mobile Applications with Angular 4 and Ionic 3Mobile Applications with Angular 4 and Ionic 3
Mobile Applications with Angular 4 and Ionic 3
 
Android Apps Using C# With Visual Studio And Xamarin
Android Apps Using C# With Visual Studio And XamarinAndroid Apps Using C# With Visual Studio And Xamarin
Android Apps Using C# With Visual Studio And Xamarin
 
End to-end native iOS, Android and Windows apps wtih Xamarin
End to-end native iOS, Android and Windows apps wtih XamarinEnd to-end native iOS, Android and Windows apps wtih Xamarin
End to-end native iOS, Android and Windows apps wtih Xamarin
 
Safari App extensions cleared up
Safari App extensions cleared upSafari App extensions cleared up
Safari App extensions cleared up
 
Cross Platform Mobile Development
Cross Platform Mobile DevelopmentCross Platform Mobile Development
Cross Platform Mobile Development
 
Ionic adventures - Hybrid Mobile App Development rocks
Ionic adventures - Hybrid Mobile App Development rocksIonic adventures - Hybrid Mobile App Development rocks
Ionic adventures - Hybrid Mobile App Development rocks
 
Native iOS and Android Development with Xamarin
Native iOS and Android Development with XamarinNative iOS and Android Development with Xamarin
Native iOS and Android Development with Xamarin
 
Build a lego app with CocoaPods
Build a lego app with CocoaPodsBuild a lego app with CocoaPods
Build a lego app with CocoaPods
 
Ultimate Productivity Tools
Ultimate Productivity ToolsUltimate Productivity Tools
Ultimate Productivity Tools
 
Cross platform development
Cross platform developmentCross platform development
Cross platform development
 
Ionic Crash Course! Hack-a-ton SF
Ionic Crash Course! Hack-a-ton SFIonic Crash Course! Hack-a-ton SF
Ionic Crash Course! Hack-a-ton SF
 
Appium ppt
Appium pptAppium ppt
Appium ppt
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
 
Building Your First Xamarin.Forms App
Building Your First Xamarin.Forms AppBuilding Your First Xamarin.Forms App
Building Your First Xamarin.Forms App
 
Workshop Ionic Framework - CC FE & UX
Workshop Ionic Framework - CC FE & UXWorkshop Ionic Framework - CC FE & UX
Workshop Ionic Framework - CC FE & UX
 
Hybrid Mobile App Development - Xamarin
Hybrid Mobile App Development - XamarinHybrid Mobile App Development - Xamarin
Hybrid Mobile App Development - Xamarin
 
MOBILE APP DEVELOPMENT Cesaconf'18
MOBILE APP DEVELOPMENT Cesaconf'18MOBILE APP DEVELOPMENT Cesaconf'18
MOBILE APP DEVELOPMENT Cesaconf'18
 
Ionic CLI Adventures
Ionic CLI AdventuresIonic CLI Adventures
Ionic CLI Adventures
 
Mobile Architecture Comparison
Mobile Architecture ComparisonMobile Architecture Comparison
Mobile Architecture Comparison
 
JavaScript : One To Many
JavaScript : One To ManyJavaScript : One To Many
JavaScript : One To Many
 

Similar to How we migrated our huge AngularJS app from CoffeeScript to TypeScript

Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
Troy Miles
 
Microsoft Robotics Developer Studio
Microsoft Robotics Developer StudioMicrosoft Robotics Developer Studio
Microsoft Robotics Developer Studio
Alp Çoker
 

Similar to How we migrated our huge AngularJS app from CoffeeScript to TypeScript (20)

Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3Angular JS 2_0 BCS CTO_in_Res V3
Angular JS 2_0 BCS CTO_in_Res V3
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
Introduction to Angular for .NET Developers
Introduction to Angular for .NET DevelopersIntroduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
 
AngularJS Anatomy & Directives
AngularJS Anatomy & DirectivesAngularJS Anatomy & Directives
AngularJS Anatomy & Directives
 
How to use apolloJS on React ?
How to use apolloJS on React ?How to use apolloJS on React ?
How to use apolloJS on React ?
 
Collab365 - AngularJS & Office 365 Unified API : A match made in heaven!
Collab365 - AngularJS & Office 365 Unified API : A match made in heaven!Collab365 - AngularJS & Office 365 Unified API : A match made in heaven!
Collab365 - AngularJS & Office 365 Unified API : A match made in heaven!
 
The Javascript Ecosystem
The Javascript EcosystemThe Javascript Ecosystem
The Javascript Ecosystem
 
Comparison Between Angular 11 vs 12 vs 13.pdf
Comparison Between Angular 11 vs 12 vs 13.pdfComparison Between Angular 11 vs 12 vs 13.pdf
Comparison Between Angular 11 vs 12 vs 13.pdf
 
Developing ionic apps for android and ios
Developing ionic apps for android and iosDeveloping ionic apps for android and ios
Developing ionic apps for android and ios
 
Mobile Development with PhoneGap
Mobile Development with PhoneGapMobile Development with PhoneGap
Mobile Development with PhoneGap
 
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
 
Using Azure Functions for Integration
Using Azure Functions for IntegrationUsing Azure Functions for Integration
Using Azure Functions for Integration
 
Angular Js
Angular JsAngular Js
Angular Js
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
 
Difference Between Angular and AngularJS.pdf
Difference Between Angular and AngularJS.pdfDifference Between Angular and AngularJS.pdf
Difference Between Angular and AngularJS.pdf
 
Microsoft Robotics Developer Studio
Microsoft Robotics Developer StudioMicrosoft Robotics Developer Studio
Microsoft Robotics Developer Studio
 
AngularJs - From Heedless Meddler to Superheroic Assistant
AngularJs - From Heedless Meddler to Superheroic AssistantAngularJs - From Heedless Meddler to Superheroic Assistant
AngularJs - From Heedless Meddler to Superheroic Assistant
 

More from Luka Zakrajšek (7)

Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math ops
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyists
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
SOA with Thrift and Finagle
SOA with Thrift and FinagleSOA with Thrift and Finagle
SOA with Thrift and Finagle
 
AngularJS
AngularJSAngularJS
AngularJS
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

How we migrated our huge AngularJS app from CoffeeScript to TypeScript