Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In typescript, what is the return type of a function that returns a void function?

I am adding return type values to my functions based on comments I have received in a code review and I don't know what to assign the return type to on this function:

function mysteryTypeFunction(): mysteryType {
    return function(): void {
        console.log('Doing some work!');
    };
}

What is the mysteryType for this function?

like image 323
apollowebdesigns Avatar asked Sep 02 '25 16:09

apollowebdesigns


1 Answers

Typescript will infer the return type, and the easiest way to find out what it infers is to hover over the symbol:

enter image description here

As we can see the return type is () => void. Which is a function signature of a function with no argument (the () part), that returns void (the => void part).

function mysteryTypeFunction(): () => void {
    return function(): void {
        console.log('Doing some work!');
    };
}
like image 102
Titian Cernicova-Dragomir Avatar answered Sep 05 '25 07:09

Titian Cernicova-Dragomir