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

PPTX
Universal Windows Platform
PPTX
Ionic framework
PPTX
Angular for rookies MS TechDays 2017
PDF
Azure App Service Helpers
PPTX
PDF
API World 2016 - API Mashup - Combining for Fun and Profit
PDF
Angular 2: Migration - SSD 2016 London
Universal Windows Platform
Ionic framework
Angular for rookies MS TechDays 2017
Azure App Service Helpers
API World 2016 - API Mashup - Combining for Fun and Profit
Angular 2: Migration - SSD 2016 London

What's hot (20)

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

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

PDF
Angular JS 2_0 BCS CTO_in_Res V3
PDF
Introduction to Angular for .NET Developers
PDF
Cross Platform Mobile Apps with the Ionic Framework
PPTX
Cross Platform Mobile Technologies
PDF
Introduction to Angular for .NET Developers
PDF
Introduction to Angular for .NET Developers
PPTX
AngularJS Anatomy & Directives
PDF
How to use apolloJS on React ?
PPTX
Collab365 - AngularJS & Office 365 Unified API : A match made in heaven!
PPTX
The Javascript Ecosystem
PDF
Comparison Between Angular 11 vs 12 vs 13.pdf
PDF
Developing ionic apps for android and ios
PDF
Mobile Development with PhoneGap
PDF
Introduction to Angular with TypeScript for .NET Developers
PPTX
Using Azure Functions for Integration
PPTX
Angular Js
PDF
Cross Platform Mobile Apps with the Ionic Framework
PDF
Difference Between Angular and AngularJS.pdf
PPT
Microsoft Robotics Developer Studio
PPTX
AngularJs - From Heedless Meddler to Superheroic Assistant
Angular JS 2_0 BCS CTO_in_Res V3
Introduction to Angular for .NET Developers
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Technologies
Introduction to Angular for .NET Developers
Introduction to Angular for .NET Developers
AngularJS Anatomy & Directives
How to use apolloJS on React ?
Collab365 - AngularJS & Office 365 Unified API : A match made in heaven!
The Javascript Ecosystem
Comparison Between Angular 11 vs 12 vs 13.pdf
Developing ionic apps for android and ios
Mobile Development with PhoneGap
Introduction to Angular with TypeScript for .NET Developers
Using Azure Functions for Integration
Angular Js
Cross Platform Mobile Apps with the Ionic Framework
Difference Between Angular and AngularJS.pdf
Microsoft Robotics Developer Studio
AngularJs - From Heedless Meddler to Superheroic Assistant
Ad

More from Luka Zakrajšek (7)

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

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
A Presentation on Artificial Intelligence
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
A Presentation on Artificial Intelligence
Dropbox Q2 2025 Financial Results & Investor Presentation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Digital-Transformation-Roadmap-for-Companies.pptx

How we migrated our huge AngularJS app from CoffeeScript to TypeScript