Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

TypeScript - interface function

0 contributions
7 points

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
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more