Languages
[Edit]
EN

TypeScript - interface function

7 points
Created by:
Palus-Bear
1016

In TypeScript it is possible to define interface for finction in following way.

1. Function interface example

interface IPrinter<T> {
    (object : T) : void;
}


let printBinary : IPrinter<number> = (value : number) : void => {
    let text = value.toString(2);

    console.log(text);
};

let printHexadeciaml : IPrinter<number> = (value : number) : void => {
    let text = value.toString(16);

    console.log(text);
};


printBinary(10);
printBinary(20);

printHexadeciaml(10);
printHexadeciaml(20);

Output:

1010
10100
a
14

Run it online here.

References

  1. Function Types - Microsoft Docs
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

TypeScript

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join