matcheek
matcheek

Reputation: 5147

What is the purpose of `(function(): Something{})` syntax?

(function() : Contract {}).

I was expecting IIFE but this colon? It’s not a label?

enter image description here

Upvotes: 0

Views: 232

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 370819

This is TypeScript syntax, not JavaScript. The colon indicates that the function will return something which is of type Contract.

For example, with

const foo = (function(): Foo {
  // lots of code
  return someExpression;
})();

this would indicate - and have TypeScript require - that the someExpression is of type Foo.

In TypeScript, noting the return type of functions like this is usually optional. Most of the time, you can omit it entirely and let TS infer it automatically if you wish. (which is what I prefer to cut down on syntax noise)

Upvotes: 4

Related Questions