I am learning type script and came across two different ways of declaring methods.
I am wondering what is the difference between the below two different function declaration g
and f
in type script. Both functions don’t return any value. Is one more preferred over the other?
interface A {
g(): void;
f: () => void;
}
class AImpl implements A {
g(): void {
console.log("Hello");
}
constructor() {
this.f = this.g;
}
f: () => void;
}
I have tried to find something on internet, specifically stack overflow but couldn’t.
I don’t quite understand the difference in syntax.
New contributor
rdal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.