Are strongly-typed functions as parameters possible in TypeScript?
@lebyy▲ 0 net votes
Problem: In TypeScript, I can declare a parameter of a function as a type Function. Is there a "type-safe" way of doing this that I am missing? For example, consider this: class Foo { save(callback: Function) : void { //Do the save var result : number = 42; //We get… Fix (from the top answer): Sure. A function's type consists of the types of its argument and its return type. Here we specify that the callback parameter's type must be "function that accepts a number and returns type any ": class Foo { save(callback: (n: number) => any) : void { callback(42); } } var foo = new Foo(); var strCallback = (res If…