1function createPerson(name: string, doAction: () => void): void {
2 console.log(`Hi, my name is ${name}.`);
3 doAction(); // doAction as a function parameter.
4}
5
6// Hi, my name is Bob.
7// performs doAction which is waveHands function.
8createPerson('Bob', waveHands());
1class Foo {
2 save(callback: (n: number) => any) : void {
3 callback(42);
4 }
5}
6var foo = new Foo();
7
8var strCallback = (result: string) : void => {
9 alert(result);
10}
11var numCallback = (result: number) : void => {
12 alert(result.toString());
13}
14
15foo.save(strCallback); // not OK
16foo.save(numCallback); // OK