Skip to main content

Interfaces as Function Types in TypeScript

· One min read

Interfaces in TypeScript can also be used to define the type of a function.

Without interface, we can define the type of a function as below:

type sumFn = (a: number, b: number) => number;

Then later we can use the type as follows:

const sum: sumFn = (a: number, b: number) => a + b;

Now let us see how to implement sumFn type using interface.

interface sumFn {
(a: number, b: number): number;
}

Note that there is no => syntax in the above snippet.