On Github saintedlama / typescript.intro
declare var document; document.title = "Hello"; // Ok because document has been declared
function vote(candidate: string, callback: (result: string) => any) { // ... } vote("BigPig", function(result: string) { if (result === "BigPig") { // ... } });
interface Point { x: number; y: number; } function getX(p: Point) { return p.x; } class CPoint { constructor (public x: number, public y: number) { } } getX(new CPoint(0, 0)); // Ok, fields match getX({ x: 0, y: 0, color: "red" }); // Extra fields Ok getX({ x: 0 }); // Error: supplied parameter does not match
class BankAccount { constructor(public balance: number) { } deposit(credit: number) { this.balance += credit; return this.balance; } } class CheckingAccount extends BankAccount { constructor(balance: number) { super(balance); } writeCheck(debit: number) { this.balance -= debit; } }
class SkinnedMesh extends THREE.Mesh { constructor(geometry, materials) { super(geometry, materials); public identityMatrix = new THREE.Matrix4(); public bones = []; public boneMatrices = []; ... } update(camera) { ... super.update(); } }See ES Harmony proposal
module M { var s = "hello"; export function f() { return s; } } M.f(); M.s; // Error, s is not exported
module math { export function sum(x, y) { return x + y; } export var pi = 3.141593; }See ES Harmony modules examples