Skip to content

Instantly share code, notes, and snippets.

@PeterOrneholm
Created February 27, 2016 15:15
Show Gist options
  • Save PeterOrneholm/475b476244f99bc93c30 to your computer and use it in GitHub Desktop.
Save PeterOrneholm/475b476244f99bc93c30 to your computer and use it in GitHub Desktop.
Example of simple TypeScript
function sumAndDisplay(left : number, right : number, prefix : string = "Result") {
var result = left + right;
alert(`${prefix}: ${result}`);
}
sumAndDisplay(1, 2);
function filter<T>(items : T[], predicate : (x : T) => boolean) : T[] {
var filtered = [];
for(let x of items){
if(predicate(x)){
filtered.push(x);
}
}
return filtered;
}
interface IPerson {
active : boolean;
name: string;
}
let people : IPerson[] = [
{ active: true, name: "Peter" },
{ active: false, name: "Olle" },
{ active: true, name: "Isabelle" }
];
let activePeople = filter(people, p => p.active);
alert(activePeople.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment