From 2c56f7bed41f7b7e26989374020d68f1f0f9ebe5 Mon Sep 17 00:00:00 2001 From: Philippe Date: Sun, 31 Aug 2014 17:57:44 +0200 Subject: Generics added And a few typos corrected, ready for pull request --- typescript.html.markdown | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/typescript.html.markdown b/typescript.html.markdown index fd22cbef..3ba1300d 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -41,7 +41,7 @@ function bigHorribleAlert(): void { //Functions are first class citizens, support the lambda "fat arrow" syntax and use type inference //All examples are equivalent, the same signature will be infered by the compiler, and same JavaScript will be emitted var f1 = function(i: number) : number { return i * i; } -var f2 = function(i: number) { return i * i; } //Return type infered #TODO bug! +var f2 = function(i: number) { return i * i; } //Return type infered var f3 = (i : number) : number => { return i * i; } var f4 = (i: number) => { return i * i; } //Return type infered var f5 = (i: number) => i * i; //Return type infered, one-liner means no return keyword needed @@ -119,12 +119,30 @@ module Geometry { var s1 = new Geometry.Square(5); -//..Local alias for rreferencing a module +//..Local alias for referencing a module import G = Geometry; var s2 = new G.Square(10); //Generics +//..Classes +class Tuple { + constructor(public item1: T1, public item2: T2) { + } +} + +//..Interfaces +interface Pair { + item1: T; + item2: T; +} + +//..And functions +var pairToTuple = function(p: Pair) { + return new Tuple(p.item1, p.item2); +}; + +var tuple = pairToTuple({ item1:"hello", item2:"world"}); //Including references to a definition file: /// -- cgit v1.2.3