Question

What is the TypeScript equivalent of this JavaScript?

(function() { 
    /* code here */ 
})();

I have tried this

() => {
    /* code here */
}

But this produces

(function() {
    /* code here */
});

I need the extra set of parenthesis at the end to perform an execution of the anonymous function.

Was it helpful?

Solution

(() => {
    /* code here */
})();

or simply use the JavaScript (which is equally valid TypeScript)

(function() { 
    /* code here */ 
})();

... depending whether you want to capture this using the fat arrow.

Playground.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top