javascript - TypeScript Unexpected token, A constructor, method, accessor or property was expected -
just trying write function within class using typescript.
class test { function add(x: number, y: number): number { return x + y; } }
this results in following error:
typescript unexpected token, constructor, method, accessor or property expected.
i copied example from: https://www.typescriptlang.org/docs/handbook/functions.html
am missing something? i'm confused!
you shouldn't use function
keyword in typescript class definition. try instead:
class test { add(x: number, y: number): number { return x + y; } }
Comments
Post a Comment