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

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 

How we migrated our huge AngularJS app from CoffeeScript to TypeScript