May 2025posted on 05.27.2025TypeScript: Callable interface Adding an interface for callable objects: interface Callable { (): string; } const myCallable: Callable = function () { return "I was called"; }; const myFunction = myCallable; const value = myFunction(); // ^? const value: string Another example with parameters: interface Callable { (numOne: number, numTwo: number): number; } const addNumbers: Callable = function (numOne, numTwo) { return numOne + numTwo; }; const myFunction = addNumbers; const value = myFunction(1, 2); // ^? const value: number No reactions yet
TypeScript: Callable interface
Adding an interface for callable objects:
Another example with parameters: