TypeScript
Fabian Vilers
@fvilers
http://www.linkedin.com/in/fvilers
Who am I ?
Founder & owner of Dev One
IT consultant with more than 15 years of experience
Microsoft .NET software architect & technology enthusiast
Father of two daughters, gamer, photographer & poker player
Who are you ?
Application scale JavaScript
development is hard
Scripting language
No static typing
Lacks of structuring mechanisms (classes, modules, interfaces)
TypeScript is a language for application-
scale JavaScript development
TypeScript is a superset of JavaScript that compiles to JavaScript
Any browser, any host, any OS
Open source
TypeScript
Starts with JavaScript
All JavaScript code is TypeScript code, simply copy and paste
All JavaScript libraries work with TypeScript
Optional static types, classes, modules
Enable scalable application development and excellent tooling
Zero cost: static types completely disappear at run-time
Ends with JavaScript
Compiles to idiomatic JavaScript
Runs in any browser or host, on any OS
Demo
TypeScript type system
Type system
Formalization of JavaScript’s types
Static representation of JavaScript’s dynamic type system
Type inference and structural typing
In practice very few type annotations are necessary
Works with existing JavaScript libraries
Declaration files can be written and maintained separately
Not « provable type safe »
Types reflect intent but do not provide guarantees
Demo
TypeScript multi-modules application
Classes and modules
Scalable application structuring
Classes, modules, and interfaces enable clear contracts between components
Aligned with emerging standards
Classes, modules, and arrow functions syntax aligns with ECMAScript 6 proposals
Support popular modules systems
CommonJS and AMD modules in any ECMAScript 3 compatible environment
What’s included ?
Compiler
Open source, written in TypeScript
Tooling
Visual Studio language service, browser hosted playground
Source Maps
Full support in upcoming Resharper 8.1
Libraries
Full static typing of DOM, jQuery, node.js,…
And more
Lots of sample and formal language specification
Resources
Official website
http://www.typescriptlang.org
Language specification (PDF)
http://go.microsoft.com/fwlink/?LinkId=267238
Repository for high quality TypeScript type definitions
https://github.com/borisyankov/DefinitelyTyped

TypeScript

  • 1.
  • 2.
    Who am I? Founder & owner of Dev One IT consultant with more than 15 years of experience Microsoft .NET software architect & technology enthusiast Father of two daughters, gamer, photographer & poker player
  • 3.
  • 4.
    Application scale JavaScript developmentis hard Scripting language No static typing Lacks of structuring mechanisms (classes, modules, interfaces)
  • 5.
    TypeScript is alanguage for application- scale JavaScript development TypeScript is a superset of JavaScript that compiles to JavaScript Any browser, any host, any OS Open source
  • 6.
    TypeScript Starts with JavaScript AllJavaScript code is TypeScript code, simply copy and paste All JavaScript libraries work with TypeScript Optional static types, classes, modules Enable scalable application development and excellent tooling Zero cost: static types completely disappear at run-time Ends with JavaScript Compiles to idiomatic JavaScript Runs in any browser or host, on any OS
  • 7.
  • 8.
    Type system Formalization ofJavaScript’s types Static representation of JavaScript’s dynamic type system Type inference and structural typing In practice very few type annotations are necessary Works with existing JavaScript libraries Declaration files can be written and maintained separately Not « provable type safe » Types reflect intent but do not provide guarantees
  • 9.
  • 10.
    Classes and modules Scalableapplication structuring Classes, modules, and interfaces enable clear contracts between components Aligned with emerging standards Classes, modules, and arrow functions syntax aligns with ECMAScript 6 proposals Support popular modules systems CommonJS and AMD modules in any ECMAScript 3 compatible environment
  • 11.
    What’s included ? Compiler Opensource, written in TypeScript Tooling Visual Studio language service, browser hosted playground Source Maps Full support in upcoming Resharper 8.1 Libraries Full static typing of DOM, jQuery, node.js,… And more Lots of sample and formal language specification
  • 12.
    Resources Official website http://www.typescriptlang.org Language specification(PDF) http://go.microsoft.com/fwlink/?LinkId=267238 Repository for high quality TypeScript type definitions https://github.com/borisyankov/DefinitelyTyped

Editor's Notes

  • #2 - Greet participants
  • #3 - Fastpresentation of myself
  • #4 Ask how many participants are developersAsk participants how large are their JavaScript applicationsAsk participants if theyfindit hard to develop and why
  • #5 - Tell participants thatthere are some alternatives to JavaScript thatgenerates JavaScript like Script#, GWT,… but they are stilltoo distant from JavaScript itself
  • #6 - TypeScriptistyped and compiles to plain JavaScript
  • #7 TypeScript works with library like Node, jQuery, Backbone,…Theses libraries are important to develop enterprise application, use them at no cost!
  • #8 Start with plain JavaScript (demonstrate that it is not typed)Show Google Closure annotations but it’s not particulary expressiveShow how TypeScript set type (string, number, boolean)Show inferred variableShow string array, () => string, structured type (a: number, b: string)Show interface Thing and structure matching + call using anonymous type + inferred return type + add a member to interface and show optional memberShow function in interface foo(s: string): string + number of argument must matchShow overloading + intellisense demo + explain that only one implementation exists + real overload + property on functionShow complex interface ThingShow make accumulator with only annotations on add function + interface + function returns an accumulator + demonstrate typing errorShow event handler + navigate to declaration
  • #10 Demonstrate the playgroundautomatic translation class Point with 2 fields as number, create a pointAdd arguments to ctorwithinitialization of the fields (conforms to ECMAScript 6)Add distance method (return Math.sqrt(this.x * this.x + this.y * this.y)Add the getaccessor (ECMAScript 6)Addstaticorigin = new Point(0, 0);Addprivatemember + demonstratethat not accessible in TS but itis in JSShow syntacticsugarwith public in ctor arguments and default valuesShow inheritancewith class Point3D and injectedhelper + addctorwith z value and call super(x, y)Overridedist()Demonstrate the wrongthiswithtrackersnippet and show thatgenerate _thisisonlygenerated if neededDemonstration modules + export keyword + open ended + namespace + import to shortennamespaceDemonstrateexternal modules: CommonJs (node) or AMD (async module definition) + nodeexecution