The use and non-use of the word function in TypeScript

2

Why when declare method in a class the compiler beeps, stating that the use of the word function is wrong.

In previous lessons from my learning to create a function, I first signed it as function .

abstract class Empregado {    
    abstract getFuncao():string;
}

class Professor extends Empregado {
    getFuncao():string {
        return "Professor";
    }
}

class Diretor extends Empregado {
    getFuncao():string {
        return "Diretor";
    }
}
    
asked by anonymous 22.05.2018 / 20:33

1 answer

1

The answer is already in the question.

Because you do not declare functions within a class, you declare methods, so it would not make sense to use function . In addition to what within a class the compiler has more control of what is happening (the syntax is less ambiguous) and can determine the beginning and end of the method, for example can not have one method inside another, but it is possible to have a function within a method.

    
22.05.2018 / 20:38