What to do with types
in JavaScript
about:TypeScript
Who‘s talkin to you
• Vedran Maršić AKA Fosna
– dev at http://axilis.hr/
– organizing programming workshops for kids
• Logo, Scratch, HTML, CSS, JavaScript
JavaScript is the assembly language
of the web!
Author unknown, mentined at:
The Birth & Death of JavaScript
A talk by Gary Bernhardt from PyCon 2014
bit.ly/RtLaCe
JavaScript alternatives
• CoffeScript
• Dart
• GWT
• Script#
• TypeScript
• ...
Folks rail against static typing but they don't
complain about JSLint. TypeScript offers
optional type annotations - it's hardly a
perversion of JavaScript.
Why does TypeScript have to be the answer to anything?
by Scott Hanselman
http://bit.ly/U1dHQR
TypeScript overview
Super set of JavaScript
Optional static typing
Static type checking at compile time
• smarter rename, refactor
• go to definition, declaration
• call hierarchy
Code sugar for classical OOP
Produces idiomatic JavaScript
by Anders Hejlsburg
Original author of Turbo Pascal
Chief architect of Delphi
Lead architect of C#
Anounced in Oct 2012
v 1.0 in Apr 2014
Open Source @ http://typescript.codeplex.com/
TypeScript trans(com)piler writen in
TypeScript
Editor support:
Visual Studio 2012+,
SublimeText, Vi, Emacs, your favorite browser
http://www.typescriptlang.org/Playground
TypeScript language features
classes, modules, function expressions
type annotations, type inference
interfaces, generics
enums
Nicked with author approval. Thank you Vlad!
https://speakerdeck.com/vladiliescu/typescript-vs-coffeescript
CLASSES, INHERITANCE
Code sugar for classical OOP
MODULES
Pesky global scope management, actually.
Going external
FUNCTION EXPRESSIONS
Fix this. Like lambda expressions.
INTERFACES
With type annotations.
http://bit.ly/1oKVaox
What impressed me the most is what
TypeScript doesn’t do. It doesn’t output
type checking into your JavaScript code.
Thoughts on TypeScript
by Nicholas C. Zakas
http://bit.ly/SkGe2y
Type definition files
Like header files in C, C++
* JQuery declaration for demo. Real declarations are verbose.
Definitely Typed
https://github.com/borisyankov/DefinitelyTyped
Of course, all valid Javascript is valid
Typescript so you can just change the file
extension and be compiling it but if you
want all the benefits you will want to take
advantage of some type annotations and
that's the manual part.
Typescript - a real world story of adoption in TFS
by Brian Harry
http://bit.ly/SkGe2y
COFFESCRIPT CLOSURE
CoffeScript has more code sugar to be fair.
Check out if interested:
CoffeScript the Good Parts
by Bruno Dević
http://slides.com/brunodevic/coffeescript-the-good-parts
DEMO
https://github.com/Fosna/TypeBoxes
Object model
FINAL THOUGHTS
Interesting quotes
Microsoft's TypeScript may be the best of
the many JavaScript front ends. It seems to
generate the most attractive code.
post on Google+
by Douglas Crockford
bit.ly/SnJzw5
And I think it should take pressure off of
the ECMAScript Standard for new features
like type declarations and classes. Anders
has shown that these can be provided nicely
by a preprocessor, so there is no need to
change the underlying language.
same post on Google+
by Douglas Crockford
bit.ly/SnJzw5
I think that JavaScript's loose typing is one of
its best features and that type checking is way
overrated. TypeScript adds sweetness, but at
a price. It is not a price I am willing to pay.
same post on Google+
by Douglas Crockford
bit.ly/SnJzw5
TypeScript feature that suprised me the most,
the quality of the JavaScript generated by the
TypeScript transcompiler and the transcompiler
itself as a tool to learn JavaScript best
practices.
Learn TypeScript to Improve Your JavaScript
by Jaime González García
http://bit.ly/1ojyhVJ
References
Spread throughout the presentation.
TypeScript: What to do with types in JavaScript

TypeScript: What to do with types in JavaScript

  • 1.
    What to dowith types in JavaScript about:TypeScript
  • 2.
    Who‘s talkin toyou • Vedran Maršić AKA Fosna – dev at http://axilis.hr/ – organizing programming workshops for kids • Logo, Scratch, HTML, CSS, JavaScript
  • 3.
    JavaScript is theassembly language of the web! Author unknown, mentined at: The Birth & Death of JavaScript A talk by Gary Bernhardt from PyCon 2014 bit.ly/RtLaCe
  • 4.
    JavaScript alternatives • CoffeScript •Dart • GWT • Script# • TypeScript • ...
  • 5.
    Folks rail againststatic typing but they don't complain about JSLint. TypeScript offers optional type annotations - it's hardly a perversion of JavaScript. Why does TypeScript have to be the answer to anything? by Scott Hanselman http://bit.ly/U1dHQR
  • 6.
    TypeScript overview Super setof JavaScript Optional static typing Static type checking at compile time • smarter rename, refactor • go to definition, declaration • call hierarchy Code sugar for classical OOP Produces idiomatic JavaScript
  • 7.
    by Anders Hejlsburg Originalauthor of Turbo Pascal Chief architect of Delphi Lead architect of C# Anounced in Oct 2012 v 1.0 in Apr 2014 Open Source @ http://typescript.codeplex.com/
  • 8.
    TypeScript trans(com)piler writenin TypeScript Editor support: Visual Studio 2012+, SublimeText, Vi, Emacs, your favorite browser http://www.typescriptlang.org/Playground
  • 9.
    TypeScript language features classes,modules, function expressions type annotations, type inference interfaces, generics enums
  • 10.
    Nicked with authorapproval. Thank you Vlad! https://speakerdeck.com/vladiliescu/typescript-vs-coffeescript
  • 13.
  • 18.
    MODULES Pesky global scopemanagement, actually.
  • 21.
  • 22.
    FUNCTION EXPRESSIONS Fix this.Like lambda expressions.
  • 26.
  • 28.
  • 29.
    What impressed methe most is what TypeScript doesn’t do. It doesn’t output type checking into your JavaScript code. Thoughts on TypeScript by Nicholas C. Zakas http://bit.ly/SkGe2y
  • 30.
    Type definition files Likeheader files in C, C++ * JQuery declaration for demo. Real declarations are verbose. Definitely Typed https://github.com/borisyankov/DefinitelyTyped
  • 31.
    Of course, allvalid Javascript is valid Typescript so you can just change the file extension and be compiling it but if you want all the benefits you will want to take advantage of some type annotations and that's the manual part. Typescript - a real world story of adoption in TFS by Brian Harry http://bit.ly/SkGe2y
  • 32.
    COFFESCRIPT CLOSURE CoffeScript hasmore code sugar to be fair. Check out if interested: CoffeScript the Good Parts by Bruno Dević http://slides.com/brunodevic/coffeescript-the-good-parts
  • 33.
  • 34.
  • 35.
  • 36.
    Microsoft's TypeScript maybe the best of the many JavaScript front ends. It seems to generate the most attractive code. post on Google+ by Douglas Crockford bit.ly/SnJzw5
  • 37.
    And I thinkit should take pressure off of the ECMAScript Standard for new features like type declarations and classes. Anders has shown that these can be provided nicely by a preprocessor, so there is no need to change the underlying language. same post on Google+ by Douglas Crockford bit.ly/SnJzw5
  • 38.
    I think thatJavaScript's loose typing is one of its best features and that type checking is way overrated. TypeScript adds sweetness, but at a price. It is not a price I am willing to pay. same post on Google+ by Douglas Crockford bit.ly/SnJzw5
  • 39.
    TypeScript feature thatsuprised me the most, the quality of the JavaScript generated by the TypeScript transcompiler and the transcompiler itself as a tool to learn JavaScript best practices. Learn TypeScript to Improve Your JavaScript by Jaime González García http://bit.ly/1ojyhVJ
  • 40.