13

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.

1 Answer 1

20
(() => {
    /* 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.