Why am I encountering an error when trying to define an object method like this:
export class Helper {
function add(x: number, y: number): number {
return x + y;
}
}
The error message reads as follows:
Unexpected token. A constructor, method, accessor, or property was expected.
I have referenced the example on https://www.typescriptlang.org/docs/handbook/functions.html, but despite following it closely, I still encounter this issue. Interestingly, removing the function
keyword resolves the error, although this seems to contradict the information provided in the official TypeScript documentation.