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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

python - Error: Unresolved reference 'selenium' What is the reason? -

php - Need to store a large amount of data in session with CI 3 but on storing large data in session it is itself destorying automatically -