How can I define a return type of void for a function in a Typescript interface? How can I define a return type of void for a function in a Typescript interface? typescript typescript

How can I define a return type of void for a function in a Typescript interface?


You have two options for syntax for a function-typed interface member, which are equivalent here:

interface IStateService {    network: (action: string) => void;}

or

interface IStateService {    network(action: string): void;}


That is close to the "type literal" syntax, but the braces are required for that:

interface IStateService {    network: { (action: string): void; }}

This is the full syntax, and allows defining overloads, like this:

interface IStateService {    network: {        (): string;        (action: string): void;    }}