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 -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -