fastcodejava
fastcodejava

Reputation: 41087

Unable to define a method in typescript file in the simple way

I'm trying to define a method in the simple way:

   method(arg: string): any {
      // code
   }

But it is not working.

If I define it like this then it works:

   const method = ((arg: string) => {
      // code
   });

Why can't I define the method in the simple way?

Upvotes: 0

Views: 28

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30082

Outside of a class, that syntax isn't valid. If you want to declare a named function, some other options are:

function method(arg: string) : any {
}

const method = function(arg: string) : any {
};

Upvotes: 2

Related Questions